From 5fd274453d9c25b5a1fdbff0b172d436c82fbd1b Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Fri, 2 Aug 2024 15:04:51 +0200 Subject: [PATCH] Upgrade to ESLint 9 --- .editorconfig | 2 +- .eslintrc.json | 32 ------------------------ .markdownlint.json | 1 + .markdownlintignore | 2 ++ eslint.config.mjs | 61 +++++++++++++++++++++++++++++++++++++++++++++ package.json | 23 +++++++++-------- 6 files changed, 78 insertions(+), 43 deletions(-) delete mode 100644 .eslintrc.json create mode 100644 .markdownlintignore create mode 100644 eslint.config.mjs diff --git a/.editorconfig b/.editorconfig index 1821b96..61d93da 100644 --- a/.editorconfig +++ b/.editorconfig @@ -9,7 +9,7 @@ trim_trailing_whitespace = true [*.html] indent_style = tab -[*.js] +[*.{js,mjs}] indent_style = tab [*.json] diff --git a/.eslintrc.json b/.eslintrc.json deleted file mode 100644 index 14d8e9f..0000000 --- a/.eslintrc.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "env": { - "node": true - }, - "extends": [ - "eslint:recommended", - "standard" - ], - "rules": { - "comma-dangle": ["warn", "always-multiline"], - "eqeqeq": "off", - "indent": ["warn", "tab", { "SwitchCase": 1 }], - "linebreak-style": ["error", "unix"], - "max-len": ["warn", 160], - "no-tabs": "off", - "semi": ["warn", "always"], - "space-before-function-paren": ["warn", { - "anonymous": "always", - "named": "never", - "asyncArrow": "always" - }] - }, - "plugins": [ - "html" - ], - "settings": { - "html/html-extensions": [".html"], - "html/indent": "tab", - "html/report-bad-indent": "warn" - }, - "root": true -} diff --git a/.markdownlint.json b/.markdownlint.json index fce123e..9fdfa04 100644 --- a/.markdownlint.json +++ b/.markdownlint.json @@ -12,6 +12,7 @@ "no-multiple-blanks": { "maximum": 2 }, + "no-trailing-spaces": true, "ul-indent": false, "ul-style": { "style": "consistent" diff --git a/.markdownlintignore b/.markdownlintignore new file mode 100644 index 0000000..c8dbc49 --- /dev/null +++ b/.markdownlintignore @@ -0,0 +1,2 @@ +.git/ +node_modules/ diff --git a/eslint.config.mjs b/eslint.config.mjs new file mode 100644 index 0000000..1f4ef68 --- /dev/null +++ b/eslint.config.mjs @@ -0,0 +1,61 @@ +import globals from "globals"; +import html from "eslint-plugin-html"; +import js from "@eslint/js"; +import neostandard, { resolveIgnoresFromGitignore } from 'neostandard'; +import stylistic from '@stylistic/eslint-plugin'; + +export default [ + { + files: ["**/*.js"], + languageOptions: { + globals: { + ...globals.browser, + }, + sourceType: "script", + }, + }, + { + files: ["**/*.html"], + plugins: { html }, + settings: { + "html/indent": "tab", + "html/report-bad-indent": "error", + }, + }, + { + ignores: [ + ...resolveIgnoresFromGitignore(), + ], + }, + js.configs.recommended, + // stylistic.configs['recommended-flat'], + ...neostandard(), + { + plugins: { + "@stylistic": stylistic, + }, + rules: { + "camelcase": "off", + "eqeqeq": "off", + "no-empty": ["error", { "allowEmptyCatch": true }], + "no-unused-vars": ["error", { + "args": "none", + "caughtErrors": "none", + }], + "object-shorthand": ["warn", "consistent"], + "yoda": "off", + "@stylistic/indent": ["warn", "tab", { "SwitchCase": 1 }], + "@stylistic/linebreak-style": ["error", "unix"], + "@stylistic/max-len": ["warn", 165], + "@stylistic/no-tabs": "off", + "@stylistic/quotes": ["off", "single", { "avoidEscape": true }], + "@stylistic/quote-props": ["warn", "consistent"], + "@stylistic/semi": ["warn", "always"], + "@stylistic/space-before-function-paren": ["warn", { + "anonymous": "always", + "asyncArrow": "always", + "named": "never", + }], + }, + }, +]; diff --git a/package.json b/package.json index c5cab18..959308e 100644 --- a/package.json +++ b/package.json @@ -28,19 +28,22 @@ "url": "https://github.com/alexandrainst/node-red-contrib-mock-cli.git" }, "devDependencies": { - "eslint": "^8.53.0", - "eslint-config-standard": "^17.1.0", - "eslint-plugin-html": "^8.0.0", - "eslint-plugin-import": "^2.29.0", - "eslint-plugin-n": "^16.2.0", - "eslint-plugin-promise": "^6.1.1" + "eslint": "^9.8.0", + "@eslint/js": "^9.8.0", + "eslint-plugin-html": "^8.1.1", + "globals": "^15.9.0", + "markdownlint-cli": "^0.41.0", + "neostandard": "^0.11.2", + "node-red-contrib-mock-cli": "^1.4.1" }, "scripts": { + "eslint": "eslint .", + "eslint_fix": "eslint --fix .", + "markdownlint": "markdownlint '**/*.md'", + "markdownlint_fix": "markdownlint --fix '**/*.md'", + "fix": "npm run rtlcss && npm run eslint_fix && npm run markdownlint_fix", + "pretest": "npm run eslint && npm run markdownlint", "start": "node ./index.js", - "eslint": "eslint --ext .js,.html .", - "eslint_fix": "eslint --fix --ext .js,.html .", - "fix": "npm run eslint_fix", - "pretest": "npm run-script eslint", "test": "echo '{\"payload\":3}' | node ./test.js test-node --multiplyBy='5' | grep -q '{\"payload\":15}' && echo 'OK'" } }