From 3430d798025d21265ab6e29396db28fcacec4b34 Mon Sep 17 00:00:00 2001 From: Tomify Date: Wed, 26 Jun 2024 14:09:23 -0400 Subject: [PATCH 1/3] Added jest config --- index.js | 78 ++++-------------------------------------------- jest.js | 29 ++++++++++++++++++ package.json | 12 ++++---- rules/default.js | 74 +++++++++++++++++++++++++++++++++++++++++++++ rules/jest.js | 7 +++++ 5 files changed, 122 insertions(+), 78 deletions(-) create mode 100644 jest.js create mode 100644 rules/default.js create mode 100644 rules/jest.js diff --git a/index.js b/index.js index c0e4966..5baed76 100644 --- a/index.js +++ b/index.js @@ -4,80 +4,14 @@ module.exports = { es6: true, node: false }, - extends: ["airbnb"], + extends: [ + "airbnb" + ].concat([ + "./rules/default" + ].map(require.resolve)), parser: "@babel/eslint-parser", plugins: ["@babel"], - rules: { - "@babel/object-curly-spacing": "error", // Replace non-babel version - "arrow-parens": ["error", "always"], // Consistency - "class-methods-use-this": "off", // Allows methods to be overridden - "comma-dangle": ["error", "never"], // Unnecessary - "consistent-return": "off", // Makes it hard to return early for conditionals - "func-names": "off", // Unnecessary and unused with arrow functions - "jsx-a11y/label-has-for": ["error", { - components: [], - required: { - some: ["nesting", "id"], - }, - allowChildren: false, - }], // Unnecessary to have nesting for both - "keyword-spacing": ["error", { - after: false, - before: false, - overrides: { - as: {before: true, after: true}, - case: {before: true, after: true}, - catch: {before: true, after: false}, - const: {before: true, after: true}, - default: {before: true, after: true}, - else: {before: true, after: true}, - export: {before: true, after: true}, - from: {before: true, after: true}, - import: {before: true, after: true}, - let: {before: true, after: true}, - return: {before: true, after: true}, - this: {before: true, after: true}, - try: {before: true, after: true} - } - }], // Whitespace - Preference - "lines-between-class-members": ["error", "never"], - "no-else-return": "off", // Allows more functional styles - "no-lonely-if": "off", // Allows more readable conditions - "no-multiple-empty-lines": ["error", {max: 1, maxBOF: 0, maxEOF: 0}], // Little stricter - "no-promise-executor-return": "off", // Makes it hard to return early for conditions - "no-underscore-dangle": "off", // Doesn't allow `const key = _key.toLowerCase()` - "no-unused-expressions": ["error", {allowShortCircuit: true, allowTernary: true}], - "object-curly-newline": ["error", {multiline: true, consistent: true}], - "object-curly-spacing": "off", // Incompatible with babel/object-curly-spacing - "prefer-destructuring": ["error", { - VariableDeclarator: { - array: false, - object: true, - }, - AssignmentExpression: { - array: false, - object: false, - }, - }, { - enforceForRenamedProperties: false, - }], // Assignment expression looks funky with parens - "quote-props": ["error", "consistent-as-needed", {keywords: false}], - "quotes": ["error", "double", {allowTemplateLiterals: true}], - "react/destructuring-assignment": "off", // Overactive and solved by prefer-destructuring - "react/function-component-definition": ["error", { - namedComponents: ["function-declaration", "function-expression"], - unnamedComponents: "arrow-function" - }], // Allows simple arrow components - "react/jsx-boolean-value": ["error", "always"], // Prefer explicit - "react/jsx-filename-extension": "off", // Unnecessary - "react/jsx-one-expression-per-line": "off", // Creates unnecessary white space issues - "react/jsx-props-no-spreading": "off", // Unnecessary - "react/no-did-update-set-state": "off", // Makes hacks needed for prop change triggers - "react/prefer-stateless-function": "off", // Prefer React - "react/react-in-jsx-scope": "off", // Global React - "react/static-property-placement": ["error", "static public field"], // Airbnb will catch up - "space-before-function-paren": ["error", "never"] // Whitespace - Preference - }, + rules: {}, settings: { "import/resolver": "webpack", react: {version: "detect"} diff --git a/jest.js b/jest.js new file mode 100644 index 0000000..72b01f1 --- /dev/null +++ b/jest.js @@ -0,0 +1,29 @@ +module.exports = { + env: { + browser: true, + es6: true, + node: true + }, + extends: [ + "airbnb", + "plugin:jest/recommended" + ].concat([ + "./rules/default", + "./rules/jest" + ].map(require.resolve)), + overrides: [ + { + files: "*.config.js", + rules: { + "global-require": "off" + } + } + ], + parser: "@babel/eslint-parser", + plugins: ["@babel"], + rules: {}, + settings: { + "import/resolver": "webpack", + react: {version: "detect"} + } +}; diff --git a/package.json b/package.json index 0c8abc4..76753cb 100644 --- a/package.json +++ b/package.json @@ -9,11 +9,11 @@ "eslint-import-resolver-webpack": "0.x" }, "description": "Traitify's base ESLint config", - "files": [ - "index.js", - "package.json", - "README.md" - ], + "exports": { + ".": "./index.js", + "./jest": "./jest.js", + "./package.json": "./package.json" + }, "homepage": "https://github.com/traitify/eslint-config-traitify#readme", "keywords": [ "config", @@ -37,5 +37,5 @@ "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, - "version": "0.3.0" + "version": "0.4.0-alpha.0" } diff --git a/rules/default.js b/rules/default.js new file mode 100644 index 0000000..3f09968 --- /dev/null +++ b/rules/default.js @@ -0,0 +1,74 @@ +module.exports = { + rules: { + "@babel/object-curly-spacing": "error", // Replace non-babel version + "arrow-parens": ["error", "always"], // Consistency + "class-methods-use-this": "off", // Allows methods to be overridden + "comma-dangle": ["error", "never"], // Unnecessary + "consistent-return": "off", // Makes it hard to return early for conditionals + "func-names": "off", // Unnecessary and unused with arrow functions + "jsx-a11y/label-has-for": ["error", { + components: [], + required: { + some: ["nesting", "id"], + }, + allowChildren: false, + }], // Unnecessary to have nesting for both + "keyword-spacing": ["error", { + after: false, + before: false, + overrides: { + as: {before: true, after: true}, + case: {before: true, after: true}, + catch: {before: true, after: false}, + const: {before: true, after: true}, + default: {before: true, after: true}, + else: {before: true, after: true}, + export: {before: true, after: true}, + from: {before: true, after: true}, + import: {before: true, after: true}, + let: {before: true, after: true}, + return: {before: true, after: true}, + this: {before: true, after: true}, + try: {before: true, after: true} + } + }], // Whitespace - Preference + "lines-between-class-members": ["error", "never"], + "no-else-return": "off", // Allows more functional styles + "no-lonely-if": "off", // Allows more readable conditions + "no-multiple-empty-lines": ["error", {max: 1, maxBOF: 0, maxEOF: 0}], // Little stricter + "no-promise-executor-return": "off", // Makes it hard to return early for conditions + "no-underscore-dangle": "off", // Doesn't allow `const key = _key.toLowerCase()` + "no-unused-expressions": ["error", {allowShortCircuit: true, allowTernary: true}], + "object-curly-newline": ["error", {multiline: true, consistent: true}], + "object-curly-spacing": "off", // Incompatible with babel/object-curly-spacing + "prefer-destructuring": ["error", { + VariableDeclarator: { + array: false, + object: true, + }, + AssignmentExpression: { + array: false, + object: false, + }, + }, { + enforceForRenamedProperties: false, + }], // Assignment expression looks funky with parens + "quote-props": ["error", "consistent-as-needed", {keywords: false}], + "quotes": ["error", "double", {allowTemplateLiterals: true}], + "react/destructuring-assignment": "off", // Overactive and solved by prefer-destructuring + "react/function-component-definition": ["error", { + namedComponents: ["function-declaration", "function-expression"], + unnamedComponents: "arrow-function" + }], // Allows simple arrow components + "react/jsx-boolean-value": ["error", "always"], // Prefer explicit + "react/jsx-filename-extension": "off", // Unnecessary + "react/jsx-one-expression-per-line": "off", // Creates unnecessary white space issues + "react/jsx-props-no-spreading": "off", // Unnecessary + "react/no-did-update-set-state": "off", // Makes hacks needed for prop change triggers + "react/prefer-stateless-function": "off", // Prefer React + "react/react-in-jsx-scope": "off", // Global React + "react/require-default-props": ["error", {functions: "defaultArguments"}], // Updated for React 18+ + "react/static-property-placement": ["error", "static public field"], // Airbnb will catch up + "space-before-function-paren": ["error", "never"] // Whitespace - Preference + } +}; diff --git a/rules/jest.js b/rules/jest.js new file mode 100644 index 0000000..6cb2378 --- /dev/null +++ b/rules/jest.js @@ -0,0 +1,7 @@ +module.exports = { + rules: { + "import/no-unresolved": "off", // Enable when jest import/resolver is fixed + "no-new": "off", // Tests are exempt + "react/prop-types": "off" // Tests are exempt + } +}; From dc0bc20ff9a43c50b2e8dd5f098c5dbdf74a4ff1 Mon Sep 17 00:00:00 2001 From: Tomify Date: Wed, 26 Jun 2024 15:35:50 -0400 Subject: [PATCH 2/3] Added updated config --- package.json | 10 ++++++++-- rules/jest.js | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 76753cb..3316e5a 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,13 @@ "name": "eslint-config-traitify", "peerDependencies": { "@babel/eslint-plugin": "7.x", - "eslint": "8.x" + "eslint": "8.x", + "eslint-import-resolver-jest": ">=3", + "eslint-plugin-jest": ">=27" + }, + "peerDependenciesMeta": { + "eslint-import-resolver-jest": {"optional": true}, + "eslint-plugin-jest": {"optional": true} }, "repository": { "type": "git", @@ -37,5 +43,5 @@ "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, - "version": "0.4.0-alpha.0" + "version": "0.4.0-alpha.1" } diff --git a/rules/jest.js b/rules/jest.js index 6cb2378..2394a48 100644 --- a/rules/jest.js +++ b/rules/jest.js @@ -2,6 +2,7 @@ module.exports = { rules: { "import/no-unresolved": "off", // Enable when jest import/resolver is fixed "no-new": "off", // Tests are exempt + "prefer-promise-reject-errors": "off", // Tests are exempt "react/prop-types": "off" // Tests are exempt } }; From 445c9f0bc0bbbfb2446779e287479c7dbf919c4d Mon Sep 17 00:00:00 2001 From: Tomify Date: Wed, 26 Jun 2024 15:42:08 -0400 Subject: [PATCH 3/3] Bumped version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3316e5a..553f7d7 100644 --- a/package.json +++ b/package.json @@ -43,5 +43,5 @@ "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, - "version": "0.4.0-alpha.1" + "version": "0.4.0" }