upgrade to eslintv9 (config format, lint to updated rules)

This commit is contained in:
Martin Raifer
2024-04-12 18:32:13 +02:00
parent bd634fb5e5
commit 211b6dde5f
14 changed files with 150 additions and 142 deletions

109
.eslintrc
View File

@@ -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"
}
}

138
config/eslint.config.mjs Normal file
View File

@@ -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
}
}
}
];

View File

@@ -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')

View File

@@ -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;

View File

@@ -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');

View File

@@ -1030,7 +1030,7 @@ export default {
try {
var regex = new RegExp(regexString);
regexes.push(regex);
} catch (e) {
} catch {
/* noop */
}
}

View File

@@ -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
}
}

View File

@@ -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;
}
}

View File

@@ -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",

View File

@@ -1,4 +1,3 @@
/* eslint-disable no-console */
/* Downloads the latest translations from Transifex */
const fs = require('fs');

View File

@@ -1,4 +1,3 @@
/* eslint-disable no-console */
const fs = require('fs');
const prettyStringify = require('json-stringify-pretty-compact');

View File

@@ -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"
}
}

View File

@@ -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);
});
});

View File

@@ -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 () {