diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 43e62e2f3..2bceacbcc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -28,3 +28,8 @@ repos: - id: detect-private-key - id: end-of-file-fixer - id: trailing-whitespace + - repo: https://github.com/eslint/eslint + rev: v7.24.0 + hooks: + - id: eslint + args: ["monkey/monkey_island/cc/ui/src/", "--fix", "--max-warnings=0"] diff --git a/.travis.yml b/.travis.yml index d57069c05..318045d68 100644 --- a/.travis.yml +++ b/.travis.yml @@ -71,7 +71,7 @@ script: - cd monkey_island/cc/ui - npm ci # See https://docs.npmjs.com/cli/ci.html - eslint ./src --quiet # Test for errors -- JS_WARNINGS_AMOUNT_UPPER_LIMIT=7 +- JS_WARNINGS_AMOUNT_UPPER_LIMIT=0 - eslint ./src --max-warnings $JS_WARNINGS_AMOUNT_UPPER_LIMIT # Test for max warnings # Build documentation diff --git a/docs/content/development/setup-development-environment.md b/docs/content/development/setup-development-environment.md index d558b11ce..af4aa5e8a 100644 --- a/docs/content/development/setup-development-environment.md +++ b/docs/content/development/setup-development-environment.md @@ -23,3 +23,11 @@ This means setting up an environment with Linux 32/64-bit with Python installed The Monkey Island is a Python backend React frontend project. Similar to the agent, the backend's requirements are listed in the matching [`requirements.txt`](https://github.com/guardicore/monkey/blob/master/monkey/monkey_island/requirements.txt). To setup a working front environment, run the instructions listed in the [`readme.txt`](https://github.com/guardicore/monkey/blob/master/monkey/monkey_island/readme.txt) + +## Pre-commit + +Pre-commit is a multi-language package manager for pre-commit hooks. It will run a set of checks when you attempt to commit. If your commit does not pass all checks, it will be reformatted and/or you'll be given a list of errors and warnings that need to be fixed before you can commit. + +Our CI system runs the same checks when pull requests are submitted. This system may report that the build has failed if the pre-commit hooks have not been run or all issues have not been resolved. + +To install and configure pre-commit, run `pip install --user pre-commit`. Next, go to the top level directory of this repository and run `pre-commit install`. Pre-commit will now run automatically whenever you `git commit`. diff --git a/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/RunOnAWS/AWSRunOptions.js b/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/RunOnAWS/AWSRunOptions.js index eba4cf0f3..a1c3cb491 100644 --- a/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/RunOnAWS/AWSRunOptions.js +++ b/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/RunOnAWS/AWSRunOptions.js @@ -56,7 +56,7 @@ const getContents = (props) => { // update existing state, not run-over let prevRes = result; for (let key in result) { - if (result.hasOwnProperty(key)) { + if (Object.prototype.hasOwnProperty.call(result, key)) { prevRes[key] = result[key]; } } diff --git a/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/RunOptions.js b/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/RunOptions.js index 3a43f1a44..db8ca17f6 100644 --- a/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/RunOptions.js +++ b/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/RunOptions.js @@ -27,7 +27,7 @@ function RunOptions(props) { .then(res => { let commandServers = res.configuration.internal.island_server.command_servers; let ipAddresses = commandServers.map(ip => { - return ip.split(":", 1); + return ip.split(':', 1); }); setIps(ipAddresses); setInitialized(true); diff --git a/monkey/monkey_island/cc/ui/src/components/reactive-graph/ReactiveGraph.js b/monkey/monkey_island/cc/ui/src/components/reactive-graph/ReactiveGraph.js index 8d8611eb6..7ffe9ae7d 100644 --- a/monkey/monkey_island/cc/ui/src/components/reactive-graph/ReactiveGraph.js +++ b/monkey/monkey_island/cc/ui/src/components/reactive-graph/ReactiveGraph.js @@ -1,6 +1,5 @@ import React from 'react'; import Graph from 'react-graph-vis'; -import Dimensions from 'react-dimensions' class GraphWrapper extends React.Component { diff --git a/monkey/monkey_island/cc/ui/src/components/report-components/SecurityReport.js b/monkey/monkey_island/cc/ui/src/components/report-components/SecurityReport.js index 8486dd547..c9fdd2c52 100644 --- a/monkey/monkey_island/cc/ui/src/components/report-components/SecurityReport.js +++ b/monkey/monkey_island/cc/ui/src/components/report-components/SecurityReport.js @@ -58,7 +58,7 @@ class ReportPageComponent extends AuthComponent { credentialTypes = { PASSWORD: 'password', HASH: 'hash', - KEY: 'key', + KEY: 'key' } issueContentTypes = { @@ -152,7 +152,7 @@ class ReportPageComponent extends AuthComponent { [this.issueContentTypes.TYPE]: this.issueTypes.DANGER }, 'zerologon_pass_restore_failed': { - [this.issueContentTypes.OVERVIEW]: zerologonOverviewWithFailedPassResetWarning, + [this.issueContentTypes.OVERVIEW]: zerologonOverviewWithFailedPassResetWarning }, 'island_cross_segment': { [this.issueContentTypes.OVERVIEW]: crossSegmentIssueOverview, @@ -437,9 +437,9 @@ class ReportPageComponent extends AuthComponent { isIssuePotentialSecurityIssue(issueName) { let issueDescriptor = this.IssueDescriptorEnum[issueName]; - return issueDescriptor.hasOwnProperty(this.issueContentTypes.TYPE) && + return Object.prototype.hasOwnProperty.call(issueDescriptor, this.issueContentTypes.TYPE) && issueDescriptor[this.issueContentTypes.TYPE] === this.issueTypes.WARNING && - issueDescriptor.hasOwnProperty(this.issueContentTypes.OVERVIEW); + Object.prototype.hasOwnProperty.call(issueDescriptor, this.issueContentTypes.OVERVIEW); } getImmediateThreats() { @@ -476,9 +476,9 @@ class ReportPageComponent extends AuthComponent { isIssueImmediateThreat(issueName) { let issueDescriptor = this.IssueDescriptorEnum[issueName]; - return issueDescriptor.hasOwnProperty(this.issueContentTypes.TYPE) && + return Object.prototype.hasOwnProperty.call(issueDescriptor, this.issueContentTypes.TYPE) && issueDescriptor[this.issueContentTypes.TYPE] === this.issueTypes.DANGER && - issueDescriptor.hasOwnProperty(this.issueContentTypes.OVERVIEW); + Object.prototype.hasOwnProperty.call(issueDescriptor, this.issueContentTypes.OVERVIEW); } getImmediateThreatsOverviews() { @@ -597,8 +597,8 @@ class ReportPageComponent extends AuthComponent { generateIssue = (issue) => { let issueDescriptor = this.IssueDescriptorEnum[issue.type]; - let reportFnc = (issue) => {}; - if (issue.hasOwnProperty('credential_type') && issue.credential_type !== null) { + let reportFnc = {}; + if (Object.prototype.hasOwnProperty.call(issue, 'credential_type') && issue.credential_type !== null) { reportFnc = issueDescriptor[this.issueContentTypes.REPORT][issue.credential_type]; } else { reportFnc = issueDescriptor[this.issueContentTypes.REPORT]; diff --git a/monkey/monkey_island/cc/ui/src/components/report-components/security/IssueDescriptor.js b/monkey/monkey_island/cc/ui/src/components/report-components/security/IssueDescriptor.js deleted file mode 100644 index 330bf3828..000000000 --- a/monkey/monkey_island/cc/ui/src/components/report-components/security/IssueDescriptor.js +++ /dev/null @@ -1,7 +0,0 @@ -class IssueDescriptor { - constructor(name, overviewComponent, reportComponent) { - this.name = name; - this.overviewComponent = overviewComponent; - this.reportComponent = reportComponent; - } -} diff --git a/monkey/monkey_island/cc/ui/src/components/report-components/security/issues/SharedPasswordsIssue.js b/monkey/monkey_island/cc/ui/src/components/report-components/security/issues/SharedPasswordsIssue.js index 2a09dbb83..5d114a520 100644 --- a/monkey/monkey_island/cc/ui/src/components/report-components/security/issues/SharedPasswordsIssue.js +++ b/monkey/monkey_island/cc/ui/src/components/report-components/security/issues/SharedPasswordsIssue.js @@ -3,11 +3,11 @@ import CollapsibleWellComponent from '../CollapsibleWell'; import {generateInfoBadges} from './utils'; export function sharedPasswordsIssueOverview() { - return (