From 9ea8c58d99c31f1d0ca8abe2d535f11e9ca68dd7 Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Fri, 9 Feb 2018 09:04:25 +0100 Subject: [PATCH] update eslint and plugins, add new rules (#3041) --- server/sonar-web/.eslintrc | 17 ++-- server/sonar-web/package.json | 6 +- .../component/ComponentNavBranchesMenu.tsx | 2 + .../main/js/app/components/search/Search.js | 2 + .../js/apps/code/components/ComponentName.tsx | 2 +- .../apps/tutorials/onboarding/AnalysisStep.js | 2 + .../tutorials/onboarding/NewProjectForm.js | 2 +- .../main/js/apps/tutorials/onboarding/Step.js | 2 +- .../tutorials/onboarding/commands/Command.js | 2 + .../src/main/js/components/charts/TreeMap.js | 2 +- .../js/components/common/SelectListItem.js | 8 +- .../src/main/js/components/issue/Issue.js | 4 +- .../main/js/components/tags/TagsSelector.tsx | 2 +- server/sonar-web/yarn.lock | 86 ++++++++++++------- 14 files changed, 91 insertions(+), 48 deletions(-) diff --git a/server/sonar-web/.eslintrc b/server/sonar-web/.eslintrc index 00b12a8d6b4..16ebf9a4f53 100644 --- a/server/sonar-web/.eslintrc +++ b/server/sonar-web/.eslintrc @@ -69,19 +69,19 @@ "no-return-await": "error", "no-self-compare": "error", "no-sequences": "error", - "no-throw-literal": "warn", + "no-throw-literal": "error", "no-unmodified-loop-condition": "error", - "no-unused-expressions": "warn", + "no-unused-expressions": "error", "no-useless-call": "error", - "no-useless-concat": "warn", - "no-useless-escape": "warn", - "no-useless-return": "warn", + "no-useless-concat": "error", + "no-useless-escape": "error", + "no-useless-return": "error", "no-void": "error", "no-with": "error", "radix": "error", "require-await": "error", "wrap-iife": "error", - "yoda": "warn", + "yoda": "error", // stylistic "camelcase": "warn", @@ -148,13 +148,18 @@ // react // TODO turn all rules to "error" eventually + "react/button-has-type": "warn", "react/display-name": "warn", "react/jsx-boolean-value": ["error", "always"], "react/jsx-no-comment-textnodes": "warn", "react/jsx-no-target-blank": "warn", "react/jsx-pascal-case": "error", + "react/jsx-sort-default-props": "warn", + "react/jsx-sort-props": "warn", + "react/no-access-state-in-setstate": "warn", "react/no-find-dom-node": "warn", "react/no-string-refs": "warn", + "react/no-this-in-sfc": "error", "react/self-closing-comp": "error", "react/sort-comp": [ "error", diff --git a/server/sonar-web/package.json b/server/sonar-web/package.json index 8089b41e562..8e3b92e3116 100644 --- a/server/sonar-web/package.json +++ b/server/sonar-web/package.json @@ -81,11 +81,11 @@ "enzyme": "3.3.0", "enzyme-adapter-react-16": "1.1.1", "enzyme-to-json": "3.3.0", - "eslint": "4.9.0", + "eslint": "4.17.0", "eslint-plugin-import": "2.8.0", "eslint-plugin-jsx-a11y": "6.0.2", "eslint-plugin-promise": "3.6.0", - "eslint-plugin-react": "7.4.0", + "eslint-plugin-react": "7.6.1", "expose-loader": "0.7.3", "extract-text-webpack-plugin": "3.0.1", "flow-bin": "^0.52.0", @@ -104,7 +104,7 @@ "style-loader": "0.19.0", "ts-jest": "22.0.1", "typescript": "2.6.2", - "typescript-eslint-parser": "11.0.0", + "typescript-eslint-parser": "12.0.0", "webpack": "3.8.1", "webpack-bundle-analyzer": "2.9.0", "webpack-dev-server": "2.9.3" diff --git a/server/sonar-web/src/main/js/app/components/nav/component/ComponentNavBranchesMenu.tsx b/server/sonar-web/src/main/js/app/components/nav/component/ComponentNavBranchesMenu.tsx index 1a303440818..1ac0cc50ae9 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/ComponentNavBranchesMenu.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/ComponentNavBranchesMenu.tsx @@ -91,6 +91,8 @@ export default class ComponentNavBranchesMenu extends React.PureComponent */) => ( + // keep this "useless" concatentation for the readability reason + // eslint-disable-next-line no-useless-concat
{lines.join(' ' + '\\' + '\n' + '  ')}
); diff --git a/server/sonar-web/src/main/js/apps/tutorials/onboarding/NewProjectForm.js b/server/sonar-web/src/main/js/apps/tutorials/onboarding/NewProjectForm.js index 143e19e1fc9..0e7a96a5b46 100644 --- a/server/sonar-web/src/main/js/apps/tutorials/onboarding/NewProjectForm.js +++ b/server/sonar-web/src/main/js/apps/tutorials/onboarding/NewProjectForm.js @@ -68,7 +68,7 @@ export default class NewProjectForm extends React.PureComponent { } }; - sanitizeProjectKey = (projectKey /*: string */) => projectKey.replace(/[^a-zA-Z0-9-_\.:]/, ''); + sanitizeProjectKey = (projectKey /*: string */) => projectKey.replace(/[^-_a-zA-Z0-9.:]/, ''); handleProjectKeyChange = (event /*: { target: HTMLInputElement } */) => { this.setState({ projectKey: this.sanitizeProjectKey(event.target.value) }); diff --git a/server/sonar-web/src/main/js/apps/tutorials/onboarding/Step.js b/server/sonar-web/src/main/js/apps/tutorials/onboarding/Step.js index 49178149921..572eb59b49b 100644 --- a/server/sonar-web/src/main/js/apps/tutorials/onboarding/Step.js +++ b/server/sonar-web/src/main/js/apps/tutorials/onboarding/Step.js @@ -42,7 +42,7 @@ export default function Step(props /*: Props */) { const clickable = !props.open && props.finished; const handleClick = (event /*: Event */) => { - event.preventDefault; + event.preventDefault(); props.onOpen(); }; diff --git a/server/sonar-web/src/main/js/apps/tutorials/onboarding/commands/Command.js b/server/sonar-web/src/main/js/apps/tutorials/onboarding/commands/Command.js index ab46a73e512..5e3706585f2 100644 --- a/server/sonar-web/src/main/js/apps/tutorials/onboarding/commands/Command.js +++ b/server/sonar-web/src/main/js/apps/tutorials/onboarding/commands/Command.js @@ -30,6 +30,8 @@ type Props = { }; */ +// keep this "useless" concatentation for the readability reason +// eslint-disable-next-line no-useless-concat const s = ' \\' + '\n '; export default class Command extends React.PureComponent { diff --git a/server/sonar-web/src/main/js/components/charts/TreeMap.js b/server/sonar-web/src/main/js/components/charts/TreeMap.js index f76b3f826db..2b526fd0fe2 100644 --- a/server/sonar-web/src/main/js/components/charts/TreeMap.js +++ b/server/sonar-web/src/main/js/components/charts/TreeMap.js @@ -53,7 +53,7 @@ export default class TreeMap extends React.PureComponent { i++; } const prefix = firstLabel.substr(0, i); - const prefixTokens = prefix.split(/[\s\\\/]/); + const prefixTokens = prefix.split(/[\s\\/]/); const lastPrefixPart = prefixTokens[prefixTokens.length - 1]; return prefix.substr(0, prefix.length - lastPrefixPart.length); }; diff --git a/server/sonar-web/src/main/js/components/common/SelectListItem.js b/server/sonar-web/src/main/js/components/common/SelectListItem.js index e12f6f2af80..83926ea37df 100644 --- a/server/sonar-web/src/main/js/components/common/SelectListItem.js +++ b/server/sonar-web/src/main/js/components/common/SelectListItem.js @@ -38,11 +38,15 @@ export default class SelectListItem extends React.PureComponent { handleSelect = (evt /*: SyntheticInputEvent */) => { evt.preventDefault(); - this.props.onSelect && this.props.onSelect(this.props.item); + if (this.props.onSelect) { + this.props.onSelect(this.props.item); + } }; handleHover = () => { - this.props.onHover && this.props.onHover(this.props.item); + if (this.props.onHover) { + this.props.onHover(this.props.item); + } }; renderLink() { diff --git a/server/sonar-web/src/main/js/components/issue/Issue.js b/server/sonar-web/src/main/js/components/issue/Issue.js index d66c6e12814..0100ba16b5b 100644 --- a/server/sonar-web/src/main/js/components/issue/Issue.js +++ b/server/sonar-web/src/main/js/components/issue/Issue.js @@ -91,7 +91,9 @@ export default class Issue extends React.PureComponent { return false; }); key('m', 'issues', () => { - this.props.issue.actions.includes('assign') && this.handleAssignement('_me'); + if (this.props.issue.actions.includes('assign')) { + this.handleAssignement('_me'); + } return false; }); key('i', 'issues', () => { diff --git a/server/sonar-web/src/main/js/components/tags/TagsSelector.tsx b/server/sonar-web/src/main/js/components/tags/TagsSelector.tsx index f9ed202989c..82d42c93710 100644 --- a/server/sonar-web/src/main/js/components/tags/TagsSelector.tsx +++ b/server/sonar-web/src/main/js/components/tags/TagsSelector.tsx @@ -54,5 +54,5 @@ export default function TagsSelector(props: Props) { export function validateTag(value: string) { // Allow only a-z, 0-9, '+', '-', '#', '.' - return value.toLowerCase().replace(/[^a-z0-9\+\-#.]/gi, ''); + return value.toLowerCase().replace(/[^-a-z0-9+#.]/gi, ''); } diff --git a/server/sonar-web/yarn.lock b/server/sonar-web/yarn.lock index 5c33dbc9e47..550e6492815 100644 --- a/server/sonar-web/yarn.lock +++ b/server/sonar-web/yarn.lock @@ -175,6 +175,10 @@ acorn@^5.1.2: version "5.3.0" resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.3.0.tgz#7446d39459c54fb49a80e6ee6478149b940ec822" +acorn@^5.4.0: + version "5.4.1" + resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.4.1.tgz#fdc58d9d17f4a4e98d102ded826a9b9759125102" + add-dom-event-listener@1.x: version "1.0.2" resolved "https://registry.yarnpkg.com/add-dom-event-listener/-/add-dom-event-listener-1.0.2.tgz#8faed2c41008721cf111da1d30d995b85be42bed" @@ -200,7 +204,7 @@ ajv@^4.9.1: co "^4.6.0" json-stable-stringify "^1.0.1" -ajv@^5.0.0, ajv@^5.1.0, ajv@^5.1.5, ajv@^5.2.0, ajv@^5.2.3: +ajv@^5.0.0, ajv@^5.1.0, ajv@^5.1.5, ajv@^5.2.3: version "5.3.0" resolved "https://registry.yarnpkg.com/ajv/-/ajv-5.3.0.tgz#4414ff74a50879c208ee5fdc826e32c303549eda" dependencies: @@ -209,6 +213,15 @@ ajv@^5.0.0, ajv@^5.1.0, ajv@^5.1.5, ajv@^5.2.0, ajv@^5.2.3: fast-json-stable-stringify "^2.0.0" json-schema-traverse "^0.3.0" +ajv@^5.3.0: + version "5.5.2" + resolved "https://registry.yarnpkg.com/ajv/-/ajv-5.5.2.tgz#73b5eeca3fab653e3d3f9422b341ad42205dc965" + dependencies: + co "^4.6.0" + fast-deep-equal "^1.0.0" + fast-json-stable-stringify "^2.0.0" + json-schema-traverse "^0.3.0" + align-text@^0.1.1, align-text@^0.1.3: version "0.1.4" resolved "https://registry.yarnpkg.com/align-text/-/align-text-0.1.4.tgz#0cd90a561093f35d0a99256c22b7069433fad117" @@ -2131,7 +2144,7 @@ debug@2.6.9, debug@^2.2.0, debug@^2.3.3, debug@^2.6.0, debug@^2.6.6, debug@^2.6. dependencies: ms "2.0.0" -debug@^3.0.1, debug@^3.1.0: +debug@^3.1.0: version "3.1.0" resolved "https://registry.yarnpkg.com/debug/-/debug-3.1.0.tgz#5bb5a0672628b64149566ba16819e61518c67261" dependencies: @@ -2301,12 +2314,11 @@ doctrine@1.5.0: esutils "^2.0.2" isarray "^1.0.0" -doctrine@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/doctrine/-/doctrine-2.0.0.tgz#c73d8d2909d22291e1a007a395804da8b665fe63" +doctrine@^2.0.2, doctrine@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/doctrine/-/doctrine-2.1.0.tgz#5cd01fc101621b42c4cd7f5d1a66243716d3f39d" dependencies: esutils "^2.0.2" - isarray "^1.0.0" dom-align@1.x: version "1.6.5" @@ -2667,14 +2679,14 @@ eslint-plugin-promise@3.6.0: version "3.6.0" resolved "https://registry.yarnpkg.com/eslint-plugin-promise/-/eslint-plugin-promise-3.6.0.tgz#54b7658c8f454813dc2a870aff8152ec4969ba75" -eslint-plugin-react@7.4.0: - version "7.4.0" - resolved "https://registry.yarnpkg.com/eslint-plugin-react/-/eslint-plugin-react-7.4.0.tgz#300a95861b9729c087d362dd64abcc351a74364a" +eslint-plugin-react@7.6.1: + version "7.6.1" + resolved "https://registry.yarnpkg.com/eslint-plugin-react/-/eslint-plugin-react-7.6.1.tgz#5d0e908be599f0c02fbf4eef0c7ed6f29dff7633" dependencies: - doctrine "^2.0.0" + doctrine "^2.0.2" has "^1.0.1" - jsx-ast-utils "^2.0.0" - prop-types "^15.5.10" + jsx-ast-utils "^2.0.1" + prop-types "^15.6.0" eslint-scope@^3.7.1: version "3.7.1" @@ -2683,32 +2695,36 @@ eslint-scope@^3.7.1: esrecurse "^4.1.0" estraverse "^4.1.1" -eslint@4.9.0: - version "4.9.0" - resolved "https://registry.yarnpkg.com/eslint/-/eslint-4.9.0.tgz#76879d274068261b191fe0f2f56c74c2f4208e8b" +eslint-visitor-keys@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz#3f3180fb2e291017716acb4c9d6d5b5c34a6a81d" + +eslint@4.17.0: + version "4.17.0" + resolved "https://registry.yarnpkg.com/eslint/-/eslint-4.17.0.tgz#dc24bb51ede48df629be7031c71d9dc0ee4f3ddf" dependencies: - ajv "^5.2.0" + ajv "^5.3.0" babel-code-frame "^6.22.0" chalk "^2.1.0" concat-stream "^1.6.0" cross-spawn "^5.1.0" - debug "^3.0.1" - doctrine "^2.0.0" + debug "^3.1.0" + doctrine "^2.1.0" eslint-scope "^3.7.1" - espree "^3.5.1" + eslint-visitor-keys "^1.0.0" + espree "^3.5.2" esquery "^1.0.0" - estraverse "^4.2.0" esutils "^2.0.2" file-entry-cache "^2.0.0" functional-red-black-tree "^1.0.1" glob "^7.1.2" - globals "^9.17.0" + globals "^11.0.1" ignore "^3.3.3" imurmurhash "^0.1.4" inquirer "^3.0.6" is-resolvable "^1.0.0" js-yaml "^3.9.1" - json-stable-stringify "^1.0.1" + json-stable-stringify-without-jsonify "^1.0.1" levn "^0.3.0" lodash "^4.17.4" minimatch "^3.0.2" @@ -2725,11 +2741,11 @@ eslint@4.9.0: table "^4.0.1" text-table "~0.2.0" -espree@^3.5.1: - version "3.5.1" - resolved "https://registry.yarnpkg.com/espree/-/espree-3.5.1.tgz#0c988b8ab46db53100a1954ae4ba995ddd27d87e" +espree@^3.5.2: + version "3.5.3" + resolved "https://registry.yarnpkg.com/espree/-/espree-3.5.3.tgz#931e0af64e7fbbed26b050a29daad1fc64799fa6" dependencies: - acorn "^5.1.1" + acorn "^5.4.0" acorn-jsx "^3.0.0" esprima@^2.6.0: @@ -3320,7 +3336,11 @@ global-prefix@^1.0.1: is-windows "^1.0.1" which "^1.2.14" -globals@^9.17.0, globals@^9.18.0: +globals@^11.0.1: + version "11.3.0" + resolved "https://registry.yarnpkg.com/globals/-/globals-11.3.0.tgz#e04fdb7b9796d8adac9c8f64c14837b2313378b0" + +globals@^9.18.0: version "9.18.0" resolved "https://registry.yarnpkg.com/globals/-/globals-9.18.0.tgz#aa3896b3e69b487f17e31ed2143d69a8e30c2d8a" @@ -4535,6 +4555,10 @@ json-schema@0.2.3: version "0.2.3" resolved "https://registry.yarnpkg.com/json-schema/-/json-schema-0.2.3.tgz#b480c892e59a2f05954ce727bd3f2a4e882f9e13" +json-stable-stringify-without-jsonify@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz#9db7b59496ad3f3cfef30a75142d2d930ad72651" + json-stable-stringify@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/json-stable-stringify/-/json-stable-stringify-1.0.1.tgz#9a759d39c5f2ff503fd5300646ed445f88c4f9af" @@ -4582,7 +4606,7 @@ jsx-ast-utils@^1.4.0: version "1.4.1" resolved "https://registry.yarnpkg.com/jsx-ast-utils/-/jsx-ast-utils-1.4.1.tgz#3867213e8dd79bf1e8f2300c0cfc1efb182c0df1" -jsx-ast-utils@^2.0.0: +jsx-ast-utils@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/jsx-ast-utils/-/jsx-ast-utils-2.0.1.tgz#e801b1b39985e20fffc87b40e3748080e2dcac7f" dependencies: @@ -7526,9 +7550,9 @@ typedarray@^0.0.6: version "0.0.6" resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" -typescript-eslint-parser@11.0.0: - version "11.0.0" - resolved "https://registry.yarnpkg.com/typescript-eslint-parser/-/typescript-eslint-parser-11.0.0.tgz#37dba6a0130dd307504aa4b4b21b0d3dc7d4e9f2" +typescript-eslint-parser@12.0.0: + version "12.0.0" + resolved "https://registry.yarnpkg.com/typescript-eslint-parser/-/typescript-eslint-parser-12.0.0.tgz#caea4b4e89e83f25765b310b924a03ba95a6dd19" dependencies: lodash.unescape "4.0.1" semver "5.4.1" -- 2.39.5