Skip to content

Commit 61bc2ce

Browse files
authored
Add test config (#2)
* Added jest config * Added updated config * Bumped version
1 parent 99cb638 commit 61bc2ce

File tree

5 files changed

+130
-79
lines changed

5 files changed

+130
-79
lines changed

index.js

+6-72
Original file line numberDiff line numberDiff line change
@@ -4,80 +4,14 @@ module.exports = {
44
es6: true,
55
node: false
66
},
7-
extends: ["airbnb"],
7+
extends: [
8+
"airbnb"
9+
].concat([
10+
"./rules/default"
11+
].map(require.resolve)),
812
parser: "@babel/eslint-parser",
913
plugins: ["@babel"],
10-
rules: {
11-
"@babel/object-curly-spacing": "error", // Replace non-babel version
12-
"arrow-parens": ["error", "always"], // Consistency
13-
"class-methods-use-this": "off", // Allows methods to be overridden
14-
"comma-dangle": ["error", "never"], // Unnecessary
15-
"consistent-return": "off", // Makes it hard to return early for conditionals
16-
"func-names": "off", // Unnecessary and unused with arrow functions
17-
"jsx-a11y/label-has-for": ["error", {
18-
components: [],
19-
required: {
20-
some: ["nesting", "id"],
21-
},
22-
allowChildren: false,
23-
}], // Unnecessary to have nesting for both
24-
"keyword-spacing": ["error", {
25-
after: false,
26-
before: false,
27-
overrides: {
28-
as: {before: true, after: true},
29-
case: {before: true, after: true},
30-
catch: {before: true, after: false},
31-
const: {before: true, after: true},
32-
default: {before: true, after: true},
33-
else: {before: true, after: true},
34-
export: {before: true, after: true},
35-
from: {before: true, after: true},
36-
import: {before: true, after: true},
37-
let: {before: true, after: true},
38-
return: {before: true, after: true},
39-
this: {before: true, after: true},
40-
try: {before: true, after: true}
41-
}
42-
}], // Whitespace - Preference
43-
"lines-between-class-members": ["error", "never"],
44-
"no-else-return": "off", // Allows more functional styles
45-
"no-lonely-if": "off", // Allows more readable conditions
46-
"no-multiple-empty-lines": ["error", {max: 1, maxBOF: 0, maxEOF: 0}], // Little stricter
47-
"no-promise-executor-return": "off", // Makes it hard to return early for conditions
48-
"no-underscore-dangle": "off", // Doesn't allow `const key = _key.toLowerCase()`
49-
"no-unused-expressions": ["error", {allowShortCircuit: true, allowTernary: true}],
50-
"object-curly-newline": ["error", {multiline: true, consistent: true}],
51-
"object-curly-spacing": "off", // Incompatible with babel/object-curly-spacing
52-
"prefer-destructuring": ["error", {
53-
VariableDeclarator: {
54-
array: false,
55-
object: true,
56-
},
57-
AssignmentExpression: {
58-
array: false,
59-
object: false,
60-
},
61-
}, {
62-
enforceForRenamedProperties: false,
63-
}], // Assignment expression looks funky with parens
64-
"quote-props": ["error", "consistent-as-needed", {keywords: false}],
65-
"quotes": ["error", "double", {allowTemplateLiterals: true}],
66-
"react/destructuring-assignment": "off", // Overactive and solved by prefer-destructuring
67-
"react/function-component-definition": ["error", {
68-
namedComponents: ["function-declaration", "function-expression"],
69-
unnamedComponents: "arrow-function"
70-
}], // Allows simple arrow components
71-
"react/jsx-boolean-value": ["error", "always"], // Prefer explicit
72-
"react/jsx-filename-extension": "off", // Unnecessary
73-
"react/jsx-one-expression-per-line": "off", // Creates unnecessary white space issues
74-
"react/jsx-props-no-spreading": "off", // Unnecessary
75-
"react/no-did-update-set-state": "off", // Makes hacks needed for prop change triggers
76-
"react/prefer-stateless-function": "off", // Prefer React
77-
"react/react-in-jsx-scope": "off", // Global React
78-
"react/static-property-placement": ["error", "static public field"], // Airbnb will catch up
79-
"space-before-function-paren": ["error", "never"] // Whitespace - Preference
80-
},
14+
rules: {},
8115
settings: {
8216
"import/resolver": "webpack",
8317
react: {version: "detect"}

jest.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
module.exports = {
2+
env: {
3+
browser: true,
4+
es6: true,
5+
node: true
6+
},
7+
extends: [
8+
"airbnb",
9+
"plugin:jest/recommended"
10+
].concat([
11+
"./rules/default",
12+
"./rules/jest"
13+
].map(require.resolve)),
14+
overrides: [
15+
{
16+
files: "*.config.js",
17+
rules: {
18+
"global-require": "off"
19+
}
20+
}
21+
],
22+
parser: "@babel/eslint-parser",
23+
plugins: ["@babel"],
24+
rules: {},
25+
settings: {
26+
"import/resolver": "webpack",
27+
react: {version: "detect"}
28+
}
29+
};

package.json

+13-7
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
"eslint-import-resolver-webpack": "0.x"
1010
},
1111
"description": "Traitify's base ESLint config",
12-
"files": [
13-
"index.js",
14-
"package.json",
15-
"README.md"
16-
],
12+
"exports": {
13+
".": "./index.js",
14+
"./jest": "./jest.js",
15+
"./package.json": "./package.json"
16+
},
1717
"homepage": "https://github.com/traitify/eslint-config-traitify#readme",
1818
"keywords": [
1919
"config",
@@ -28,7 +28,13 @@
2828
"name": "eslint-config-traitify",
2929
"peerDependencies": {
3030
"@babel/eslint-plugin": "7.x",
31-
"eslint": "8.x"
31+
"eslint": "8.x",
32+
"eslint-import-resolver-jest": ">=3",
33+
"eslint-plugin-jest": ">=27"
34+
},
35+
"peerDependenciesMeta": {
36+
"eslint-import-resolver-jest": {"optional": true},
37+
"eslint-plugin-jest": {"optional": true}
3238
},
3339
"repository": {
3440
"type": "git",
@@ -37,5 +43,5 @@
3743
"scripts": {
3844
"test": "echo \"Error: no test specified\" && exit 1"
3945
},
40-
"version": "0.3.0"
46+
"version": "0.4.0"
4147
}

rules/default.js

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
module.exports = {
2+
rules: {
3+
"@babel/object-curly-spacing": "error", // Replace non-babel version
4+
"arrow-parens": ["error", "always"], // Consistency
5+
"class-methods-use-this": "off", // Allows methods to be overridden
6+
"comma-dangle": ["error", "never"], // Unnecessary
7+
"consistent-return": "off", // Makes it hard to return early for conditionals
8+
"func-names": "off", // Unnecessary and unused with arrow functions
9+
"jsx-a11y/label-has-for": ["error", {
10+
components: [],
11+
required: {
12+
some: ["nesting", "id"],
13+
},
14+
allowChildren: false,
15+
}], // Unnecessary to have nesting for both
16+
"keyword-spacing": ["error", {
17+
after: false,
18+
before: false,
19+
overrides: {
20+
as: {before: true, after: true},
21+
case: {before: true, after: true},
22+
catch: {before: true, after: false},
23+
const: {before: true, after: true},
24+
default: {before: true, after: true},
25+
else: {before: true, after: true},
26+
export: {before: true, after: true},
27+
from: {before: true, after: true},
28+
import: {before: true, after: true},
29+
let: {before: true, after: true},
30+
return: {before: true, after: true},
31+
this: {before: true, after: true},
32+
try: {before: true, after: true}
33+
}
34+
}], // Whitespace - Preference
35+
"lines-between-class-members": ["error", "never"],
36+
"no-else-return": "off", // Allows more functional styles
37+
"no-lonely-if": "off", // Allows more readable conditions
38+
"no-multiple-empty-lines": ["error", {max: 1, maxBOF: 0, maxEOF: 0}], // Little stricter
39+
"no-promise-executor-return": "off", // Makes it hard to return early for conditions
40+
"no-underscore-dangle": "off", // Doesn't allow `const key = _key.toLowerCase()`
41+
"no-unused-expressions": ["error", {allowShortCircuit: true, allowTernary: true}],
42+
"object-curly-newline": ["error", {multiline: true, consistent: true}],
43+
"object-curly-spacing": "off", // Incompatible with babel/object-curly-spacing
44+
"prefer-destructuring": ["error", {
45+
VariableDeclarator: {
46+
array: false,
47+
object: true,
48+
},
49+
AssignmentExpression: {
50+
array: false,
51+
object: false,
52+
},
53+
}, {
54+
enforceForRenamedProperties: false,
55+
}], // Assignment expression looks funky with parens
56+
"quote-props": ["error", "consistent-as-needed", {keywords: false}],
57+
"quotes": ["error", "double", {allowTemplateLiterals: true}],
58+
"react/destructuring-assignment": "off", // Overactive and solved by prefer-destructuring
59+
"react/function-component-definition": ["error", {
60+
namedComponents: ["function-declaration", "function-expression"],
61+
unnamedComponents: "arrow-function"
62+
}], // Allows simple arrow components
63+
"react/jsx-boolean-value": ["error", "always"], // Prefer explicit
64+
"react/jsx-filename-extension": "off", // Unnecessary
65+
"react/jsx-one-expression-per-line": "off", // Creates unnecessary white space issues
66+
"react/jsx-props-no-spreading": "off", // Unnecessary
67+
"react/no-did-update-set-state": "off", // Makes hacks needed for prop change triggers
68+
"react/prefer-stateless-function": "off", // Prefer React
69+
"react/react-in-jsx-scope": "off", // Global React
70+
"react/require-default-props": ["error", {functions: "defaultArguments"}], // Updated for React 18+
71+
"react/static-property-placement": ["error", "static public field"], // Airbnb will catch up
72+
"space-before-function-paren": ["error", "never"] // Whitespace - Preference
73+
}
74+
};

rules/jest.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
rules: {
3+
"import/no-unresolved": "off", // Enable when jest import/resolver is fixed
4+
"no-new": "off", // Tests are exempt
5+
"prefer-promise-reject-errors": "off", // Tests are exempt
6+
"react/prop-types": "off" // Tests are exempt
7+
}
8+
};

0 commit comments

Comments
 (0)