From 211b6dde5f2e3e8de09ef639d5d85a4b128ee6af Mon Sep 17 00:00:00 2001 From: Martin Raifer Date: Fri, 12 Apr 2024 18:32:13 +0200 Subject: [PATCH] upgrade to eslintv9 (config format, lint to updated rules) --- .eslintrc | 109 ------------------------- config/eslint.config.mjs | 138 ++++++++++++++++++++++++++++++++ modules/behavior/draw_way.js | 2 +- modules/core/LocationManager.js | 6 +- modules/core/preferences.js | 4 +- modules/services/osm.js | 2 +- modules/svg/local_photos.js | 2 +- modules/ui/fields/input.js | 2 +- package.json | 4 +- scripts/language_names.js | 1 - scripts/update_imagery.js | 1 - test/.eslintrc | 17 ---- test/spec/services/maprules.js | 2 +- test/spec/ui/cmd.js | 2 - 14 files changed, 150 insertions(+), 142 deletions(-) delete mode 100644 .eslintrc create mode 100644 config/eslint.config.mjs delete mode 100644 test/.eslintrc diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index e70eaad32..000000000 --- a/.eslintrc +++ /dev/null @@ -1,109 +0,0 @@ -{ - "env": { - "browser": true, - "node": true, - "es6": true - }, - "extends": [ - "eslint:recommended" - ], - "globals": { - "d3": false - }, - "parserOptions": { - "ecmaVersion": "latest", - "sourceType": "module" - }, - "rules": { - "accessor-pairs": "error", - "array-callback-return": "warn", - "arrow-spacing": "warn", - "block-scoped-var": "error", - "block-spacing": ["warn", "always"], - "brace-style": ["warn", "1tbs", { "allowSingleLine": true }], - "complexity": ["warn", 50], - "curly": ["warn", "multi-line"], - "default-case-last": "error", - "default-param-last": "error", - "dot-notation": "error", - "eqeqeq": ["error", "smart"], - "func-call-spacing": ["warn", "never"], - "grouped-accessor-pairs": "error", - "indent": ["off", 4], - "keyword-spacing": "error", - "linebreak-style": ["error", "unix"], - "no-await-in-loop": "error", - "no-caller": "error", - "no-catch-shadow": "error", - "no-console": "warn", - "no-constructor-return": "error", - "no-div-regex": "error", - "no-duplicate-imports": "warn", - "no-eq-null": "error", - "no-eval": "error", - "no-extend-native": "error", - "no-extra-bind": "error", - "no-extra-label": "error", - "no-floating-decimal": "error", - "no-global-assign": "error", - "no-implicit-coercion": ["warn", { "boolean": false, "number": false }], - "no-implied-eval": "error", - "no-invalid-this": "off", - "no-iterator": "error", - "no-labels": "error", - "no-label-var": "error", - "no-lone-blocks": "error", - "no-loop-func": "error", - "no-loss-of-precision": "error", - "no-multi-str": "error", - "no-new": "error", - "no-new-func": "error", - "no-new-wrappers": "error", - "no-octal": "error", - "no-octal-escape": "error", - "no-process-env": "error", - "no-promise-executor-return": "error", - "no-proto": "error", - "no-prototype-builtins": "off", - "no-restricted-properties": "error", - "no-return-assign": "off", - "no-return-await": "error", - "no-script-url": "error", - "no-self-compare": "error", - "no-sequences": "error", - "no-shadow": "off", - "no-shadow-restricted-names": "error", - "no-template-curly-in-string": "warn", - "no-throw-literal": "error", - "no-trailing-spaces": "warn", - "no-undef": "error", - "no-undef-init": "warn", - "no-unexpected-multiline": "error", - "no-unneeded-ternary": "error", - "no-unmodified-loop-condition": "error", - "no-unreachable": "warn", - "no-unreachable-loop": "warn", - "no-unused-expressions": "error", - "no-unused-vars": "warn", - "no-use-before-define": ["off", "nofunc"], - "no-useless-backreference": "warn", - "no-useless-call": "warn", - "no-useless-computed-key": "warn", - "no-useless-concat": "warn", - "no-useless-constructor": "warn", - "no-useless-escape": "off", - "no-useless-rename": "warn", - "no-void": "error", - "no-warning-comments": "warn", - "no-whitespace-before-property": "warn", - "no-with": "error", - "quotes": ["error", "single"], - "radix": ["error", "always"], - "require-atomic-updates": "error", - "require-await": "error", - "semi": ["error", "always"], - "semi-spacing": "error", - "space-unary-ops": "error", - "wrap-regex": "off" - } -} \ No newline at end of file diff --git a/config/eslint.config.mjs b/config/eslint.config.mjs new file mode 100644 index 000000000..ca4636444 --- /dev/null +++ b/config/eslint.config.mjs @@ -0,0 +1,138 @@ +import js from '@eslint/js'; +import globals from 'globals'; + +export default [ + js.configs.recommended, + { + files: ['**/*.js', '**/*.mjs'], + languageOptions: { + ecmaVersion: 'latest', + sourceType: 'module', + globals: { + ...globals.browser, + ...globals.es6 + } + }, + rules: { + 'accessor-pairs': 'error', + 'array-callback-return': 'warn', + 'arrow-spacing': 'warn', + 'block-scoped-var': 'error', + 'block-spacing': ['warn', 'always'], + 'brace-style': ['warn', '1tbs', { 'allowSingleLine': true }], + 'complexity': ['warn', 50], + 'curly': ['warn', 'multi-line'], + 'default-case-last': 'error', + 'default-param-last': 'error', + 'dot-notation': 'error', + 'eqeqeq': ['error', 'smart'], + 'func-call-spacing': ['warn', 'never'], + 'grouped-accessor-pairs': 'error', + 'indent': ['off', 4], + 'keyword-spacing': 'error', + 'linebreak-style': ['error', 'unix'], + 'no-await-in-loop': 'error', + 'no-caller': 'error', + 'no-catch-shadow': 'error', + 'no-console': 'warn', + 'no-constructor-return': 'error', + 'no-div-regex': 'error', + 'no-duplicate-imports': 'warn', + 'no-eq-null': 'error', + 'no-eval': 'error', + 'no-extend-native': 'error', + 'no-extra-bind': 'error', + 'no-extra-label': 'error', + 'no-floating-decimal': 'error', + 'no-global-assign': 'error', + 'no-implicit-coercion': ['warn', { 'boolean': false, 'number': false }], + 'no-implied-eval': 'error', + 'no-invalid-this': 'off', + 'no-iterator': 'error', + 'no-labels': 'error', + 'no-label-var': 'error', + 'no-lone-blocks': 'error', + 'no-loop-func': 'error', + 'no-loss-of-precision': 'error', + 'no-multi-str': 'error', + 'no-new': 'error', + 'no-new-func': 'error', + 'no-new-wrappers': 'error', + 'no-octal': 'error', + 'no-octal-escape': 'error', + 'no-process-env': 'error', + 'no-promise-executor-return': 'error', + 'no-proto': 'error', + 'no-prototype-builtins': 'off', + 'no-restricted-properties': 'error', + 'no-return-assign': 'off', + 'no-return-await': 'error', + 'no-script-url': 'error', + 'no-self-compare': 'error', + 'no-sequences': 'error', + 'no-shadow': 'off', + 'no-shadow-restricted-names': 'error', + 'no-template-curly-in-string': 'warn', + 'no-throw-literal': 'error', + 'no-trailing-spaces': 'warn', + 'no-undef': 'error', + 'no-undef-init': 'warn', + 'no-unexpected-multiline': 'error', + 'no-unneeded-ternary': 'error', + 'no-unmodified-loop-condition': 'error', + 'no-unreachable': 'warn', + 'no-unreachable-loop': 'warn', + 'no-unused-expressions': 'error', + 'no-unused-vars': 'warn', + 'no-use-before-define': ['off', 'nofunc'], + 'no-useless-backreference': 'warn', + 'no-useless-call': 'warn', + 'no-useless-computed-key': 'warn', + 'no-useless-concat': 'warn', + 'no-useless-constructor': 'warn', + 'no-useless-escape': 'off', + 'no-useless-rename': 'warn', + 'no-void': 'error', + 'no-warning-comments': 'warn', + 'no-whitespace-before-property': 'warn', + 'no-with': 'error', + 'quotes': ['error', 'single'], + 'radix': ['error', 'always'], + 'require-atomic-updates': 'error', + 'require-await': 'error', + 'semi': ['error', 'always'], + 'semi-spacing': 'error', + 'space-unary-ops': 'error', + 'wrap-regex': 'off' + } + }, + { + files: ['test/**/*.js', 'test/**/*.mjs'], + languageOptions: { + globals: { + ...globals.node, + ...globals.es6, + ...globals.mocha, + 'd3': 'readonly', + 'iD': 'readonly', + 'sinon': 'readonly', + 'happen': 'readonly', + 'fetchMock': 'readonly', + 'expect': 'writable' + } + }, + rules: { + 'no-unused-expressions': 'off' + } + }, + { + files: ['scripts/**/*.js', 'scripts/**/*.mjs', 'config/**/*.js', 'config/**/*.mjs'], + languageOptions: { + globals: { + ...globals.node, + ...globals.es6 + } + } + } +]; + diff --git a/modules/behavior/draw_way.js b/modules/behavior/draw_way.js index 29fa0aa1f..1dd0af6f9 100644 --- a/modules/behavior/draw_way.js +++ b/modules/behavior/draw_way.js @@ -497,7 +497,7 @@ export function behaviorDrawWay(context, wayID, mode, startGraph) { id: nextNode.id, properties: { target: true, entity: nextNode }, }); - } catch (ex) { + } catch { context.ui().flash .duration(4000) .iconName('#iD-icon-no') diff --git a/modules/core/LocationManager.js b/modules/core/LocationManager.js index 7940265b4..784efd51e 100644 --- a/modules/core/LocationManager.js +++ b/modules/core/LocationManager.js @@ -109,7 +109,7 @@ export class LocationManager { this._knownLocationSets.set(locationSetID, area); - } catch (err) { + } catch { obj.locationSet = { include: ['Q2'] }; // default worldwide obj.locationSetID = '+[Q2]'; } @@ -144,7 +144,7 @@ export class LocationManager { geojson.properties.id = locationSetID; this._resolved.set(locationSetID, geojson); - } catch (err) { + } catch { obj.locationSet = { include: ['Q2'] }; // default worldwide obj.locationSetID = '+[Q2]'; } @@ -244,7 +244,7 @@ export class LocationManager { let locationSetID; try { locationSetID = _loco.validateLocationSet(locationSet).id; - } catch (err) { + } catch { locationSetID = '+[Q2]'; // the world } return locationSetID; diff --git a/modules/core/preferences.js b/modules/core/preferences.js index b2a9774d9..e82d6e338 100644 --- a/modules/core/preferences.js +++ b/modules/core/preferences.js @@ -2,7 +2,7 @@ // https://github.com/openstreetmap/iD/issues/772 // http://mathiasbynens.be/notes/localstorage-pattern#comment-9 let _storage; -try { _storage = localStorage; } catch (e) {} // eslint-disable-line no-empty +try { _storage = localStorage; } catch {} // eslint-disable-line no-empty _storage = _storage || (() => { let s = {}; return { @@ -32,7 +32,7 @@ function corePreferences(k, v) { _listeners[k].forEach(handler => handler(v)); } return true; - } catch (e) { + } catch { /* eslint-disable no-console */ if (typeof console !== 'undefined') { console.error('localStorage quota exceeded'); diff --git a/modules/services/osm.js b/modules/services/osm.js index 504c6ae2d..864037d8d 100644 --- a/modules/services/osm.js +++ b/modules/services/osm.js @@ -1030,7 +1030,7 @@ export default { try { var regex = new RegExp(regexString); regexes.push(regex); - } catch (e) { + } catch { /* noop */ } } diff --git a/modules/svg/local_photos.js b/modules/svg/local_photos.js index 6300f1d28..33094125e 100644 --- a/modules/svg/local_photos.js +++ b/modules/svg/local_photos.js @@ -252,7 +252,7 @@ export function svgLocalPhotos(projection, context, dispatch) { _photos.push(photo); } } - } catch (err) { + } catch { // skip files which are not a supported image file } } diff --git a/modules/ui/fields/input.js b/modules/ui/fields/input.js index c5061b5ea..9a7ee9080 100644 --- a/modules/ui/fields/input.js +++ b/modules/ui/fields/input.js @@ -362,7 +362,7 @@ export function uiFieldText(field, context) { if (field.type === 'url' && value) { try { return (new URL(value)).href; - } catch (e) { + } catch { return null; } } diff --git a/package.json b/package.json index e371845e9..27189fead 100644 --- a/package.json +++ b/package.json @@ -33,8 +33,8 @@ "dist:svg:roentgen": "svg-sprite --shape-id-generator \"roentgen-%s\" --shape-dim-width 16 --shape-dim-height 16 --symbol --symbol-dest . --symbol-sprite dist/img/roentgen-sprite.svg svg/roentgen/*.svg", "dist:svg:temaki": "svg-sprite --symbol --symbol-dest . --shape-id-generator \"temaki-%s\" --symbol-sprite dist/img/temaki-sprite.svg node_modules/@rapideditor/temaki/icons/*.svg", "imagery": "node scripts/update_imagery.js", - "lint": "eslint config scripts test/spec modules --ext js,mjs", - "lint:fix": "eslint scripts test/spec modules --fix", + "lint": "eslint config scripts test/spec modules -c config/eslint.config.mjs", + "lint:fix": "eslint scripts test/spec modules -c config/eslint.config.mjs --fix", "start": "run-s start:watch", "start:single-build": "run-p build:js start:server", "start:watch": "run-p build:js:watch start:server", diff --git a/scripts/language_names.js b/scripts/language_names.js index 8bce6e959..63b22ace1 100644 --- a/scripts/language_names.js +++ b/scripts/language_names.js @@ -1,4 +1,3 @@ -/* eslint-disable no-console */ /* Downloads the latest translations from Transifex */ const fs = require('fs'); diff --git a/scripts/update_imagery.js b/scripts/update_imagery.js index 2094a4bc2..a7fb6dfd3 100644 --- a/scripts/update_imagery.js +++ b/scripts/update_imagery.js @@ -1,4 +1,3 @@ -/* eslint-disable no-console */ const fs = require('fs'); const prettyStringify = require('json-stringify-pretty-compact'); diff --git a/test/.eslintrc b/test/.eslintrc deleted file mode 100644 index 8d0a09855..000000000 --- a/test/.eslintrc +++ /dev/null @@ -1,17 +0,0 @@ -{ - "env": { - "browser": true, - "mocha": true - }, - "globals": { - "expect": true, - "fakeFetch": true, - "happen": false, - "iD": false, - "sinon": false, - "fetchMock": true - }, - "rules": { - "no-unused-expressions": "off" - } -} diff --git a/test/spec/services/maprules.js b/test/spec/services/maprules.js index 93a76a283..4bde43911 100644 --- a/test/spec/services/maprules.js +++ b/test/spec/services/maprules.js @@ -562,7 +562,7 @@ describe('maprules', function() { expect(issues.length).to.eql(1); expect(issue.entityIds).to.eql([entity.id]); - expect(issue.message(context)).to.eql(selector[type]); + expect(issue.message(iD.coreContext())).to.eql(selector[type]); expect(type).to.eql(issue.severity); }); }); diff --git a/test/spec/ui/cmd.js b/test/spec/ui/cmd.js index 3deb890f7..bf4554443 100644 --- a/test/spec/ui/cmd.js +++ b/test/spec/ui/cmd.js @@ -4,7 +4,6 @@ describe('iD.uiCmd', function () { var uaMock = function () { return ua; }; beforeEach(function() { - /* eslint-disable no-global-assign */ /* mock userAgent */ orig = navigator.__lookupGetter__('userAgent'); navigator.__defineGetter__('userAgent', uaMock); @@ -13,7 +12,6 @@ describe('iD.uiCmd', function () { afterEach(function() { /* restore userAgent */ navigator.__defineGetter__('userAgent', orig); - /* eslint-enable no-global-assign */ }); it('does not overwrite mac keybindings', function () {