From 680f9a9294c091a53b9894b5220b412f1ab2b89c Mon Sep 17 00:00:00 2001 From: Ricardo Costa <48949546+ripecosta@users.noreply.github.com> Date: Mon, 12 Aug 2024 17:57:36 +0100 Subject: [PATCH 1/3] style: update eslint config --- .eslintignore | 11 +++--- .eslintrc.json | 77 ++++++------------------------------------ lint-staged.config.mjs | 3 +- package.json | 3 +- 4 files changed, 20 insertions(+), 74 deletions(-) diff --git a/.eslintignore b/.eslintignore index ed39856f2..22e295c24 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,6 +1,5 @@ -**/dist/* -**/node_modules/* -**/*.min.* -**/*.ts -**/*.tsx -example/**/* \ No newline at end of file +**/dist/ +**/node_modules/ +example/**/* +**/react-i18next.js +**/react-i18next.min.js diff --git a/.eslintrc.json b/.eslintrc.json index 6ca5d97aa..d7a95721b 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -16,37 +16,12 @@ "rules": { "no-debugger": 0, "no-alert": 0, - "no-unused-vars": [ - 1, - { - "argsIgnorePattern": "res|next|^err" - } - ], - "prefer-arrow-callback": [ - "error", - { - "allowNamedFunctions": true - } - ], - "prefer-const": [ - "error", - { - "destructuring": "all" - } - ], + "no-unused-vars": [1, { "argsIgnorePattern": "res|next|^err" }], + "prefer-arrow-callback": ["error", { "allowNamedFunctions": true }], + "prefer-const": ["error", { "destructuring": "all" }], "arrow-body-style": [2, "as-needed"], - "no-unused-expressions": [ - 2, - { - "allowTaggedTemplates": true - } - ], - "no-param-reassign": [ - 2, - { - "props": false - } - ], + "no-unused-expressions": [2, { "allowTaggedTemplates": true }], + "no-param-reassign": [2, { "props": false }], "no-console": 0, "no-use-before-define": 0, "no-nested-ternary": 0, @@ -63,53 +38,23 @@ "consistent-return": 0, "react/display-name": 1, "react/no-array-index-key": 0, - "react/jsx-no-useless-fragment": [ - "error", - { - "allowExpressions": true - } - ], + "react/jsx-no-useless-fragment": ["error", { "allowExpressions": true }], "react/react-in-jsx-scope": 0, "react/prefer-stateless-function": 0, "react/forbid-prop-types": 0, "react/no-unescaped-entities": 0, "react/prop-types": 0, "jsx-a11y/accessible-emoji": 0, - "react/jsx-filename-extension": [ - 1, - { - "extensions": [".js", ".jsx"] - } - ], - "react/no-unknown-property": [ - "error", - { - "ignore": ["i18nIsDynamicList"] - } - ], + "react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }], + "react/no-unknown-property": ["error", { "ignore": ["i18nIsDynamicList"] }], "radix": 0, "no-shadow": [ 2, - { - "hoist": "all", - "allow": ["resolve", "reject", "done", "next", "err", "error"] - } - ], - "quotes": [ - 2, - "single", - { - "avoidEscape": true, - "allowTemplateLiterals": true - } + { "hoist": "all", "allow": ["resolve", "reject", "done", "next", "err", "error"] } ], + "quotes": [2, "single", { "avoidEscape": true, "allowTemplateLiterals": true }], "jsx-a11y/href-no-hash": "off", - "jsx-a11y/anchor-is-valid": [ - "warn", - { - "aspects": ["invalidHref"] - } - ], + "jsx-a11y/anchor-is-valid": ["warn", { "aspects": ["invalidHref"] }], "react/jsx-props-no-spreading": 0 } } diff --git a/lint-staged.config.mjs b/lint-staged.config.mjs index ff0f7eb0d..c427777fb 100644 --- a/lint-staged.config.mjs +++ b/lint-staged.config.mjs @@ -1,3 +1,4 @@ export default { - '*': ['prettier --write --ignore-unknown'], + '!*.?(c|m){js,ts}?(x)': ['prettier --write '], + '*.?(c|m){js,ts}?(x)': ['prettier --write --ignore-unknown', 'eslint --cache --fix --env-info'], }; diff --git a/package.json b/package.json index 3146434a9..ece86599a 100644 --- a/package.json +++ b/package.json @@ -133,7 +133,8 @@ }, "scripts": { "clean": "rimraf dist && mkdirp dist", - "lint": "eslint ./src ./test", + "lint": "eslint --cache .", + "lint:fix": "eslint --cache --fix .", "format": "prettier . --check", "format:fix": "prettier . --write --list-different", "copy": "cpy ./dist/umd/react-i18next.min.js ./dist/umd/react-i18next.js . --flat && echo '{\"type\":\"module\"}' > dist/es/package.json", From d3edde1ecd1c61bebca34fe00519d16437a9ebf3 Mon Sep 17 00:00:00 2001 From: Ricardo Costa <48949546+ripecosta@users.noreply.github.com> Date: Mon, 12 Aug 2024 17:58:44 +0100 Subject: [PATCH 2/3] style: run eslint --- icu.macro.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/icu.macro.js b/icu.macro.js index c16dfac23..9835e34ff 100644 --- a/icu.macro.js +++ b/icu.macro.js @@ -320,10 +320,8 @@ function processTrans(children, babel, componentStartIndex = 0) { return res; } -// eslint-disable-next-line no-control-regex -const leadingNewLineAndWhitespace = new RegExp('^\n\\s+', 'g'); -// eslint-disable-next-line no-control-regex -const trailingNewLineAndWhitespace = new RegExp('\n\\s+$', 'g'); +const leadingNewLineAndWhitespace = /^\n\s+/g; +const trailingNewLineAndWhitespace = /\n\s+$/g; function trimIndent(text) { const newText = text .replace(leadingNewLineAndWhitespace, '') From 709875671191feeb47dcb3f2c3cb56ec721bce26 Mon Sep 17 00:00:00 2001 From: Ricardo Costa <48949546+ripecosta@users.noreply.github.com> Date: Mon, 12 Aug 2024 18:38:20 +0100 Subject: [PATCH 3/3] chore: centralise eslint config --- .eslintrc.json | 14 +++++++++++++- test/.eslintrc.json | 9 --------- 2 files changed, 13 insertions(+), 10 deletions(-) delete mode 100644 test/.eslintrc.json diff --git a/.eslintrc.json b/.eslintrc.json index d7a95721b..9291598cb 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -56,5 +56,17 @@ "jsx-a11y/href-no-hash": "off", "jsx-a11y/anchor-is-valid": ["warn", { "aspects": ["invalidHref"] }], "react/jsx-props-no-spreading": 0 - } + }, + "overrides": [ + { + "files": ["test/*"], + "extends": ["plugin:testing-library/react", "plugin:jest-dom/recommended"], + "globals": { + "globalThis": false + }, + "rules": { + "testing-library/no-node-access": ["error", { "allowContainerFirstChild": true }] + } + } + ] } diff --git a/test/.eslintrc.json b/test/.eslintrc.json deleted file mode 100644 index 4a6cfa3ce..000000000 --- a/test/.eslintrc.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "extends": ["plugin:testing-library/react", "plugin:jest-dom/recommended"], - "globals": { - "globalThis": false - }, - "rules": { - "testing-library/no-node-access": ["error", { "allowContainerFirstChild": true }] - } -}