Skip to content

Commit 386d242

Browse files
authored
Merge pull request #114 from acelaya-forks/feature/flat-config
Feature/flat config
2 parents ac12e15 + 9f4be50 commit 386d242

File tree

4 files changed

+301
-784
lines changed

4 files changed

+301
-784
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,21 @@
66
[![Paypal Donate](https://img.shields.io/badge/Donate-paypal-blue.svg?style=flat-square&logo=paypal&colorA=cccccc)](https://acel.me/donate)
77

88
Coding standard used by Shlink JavaScript projects.
9+
10+
This library includes two ESLint configurations, the base one, and the react-specific one. Default export includes both:
11+
12+
```js
13+
// eslint.config.js
14+
import shlink from '@shlinkio/eslint-config-js-coding-standard';
15+
16+
export default shlink;
17+
```
18+
19+
If the project does not use React, you can just use the base config:
20+
21+
```js
22+
// eslint.config.js
23+
import { baseConfig } from '@shlinkio/eslint-config-js-coding-standard';
24+
25+
export default baseConfig;
26+
```

index.js

Lines changed: 109 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,115 @@
1-
module.exports = {
2-
extends: [
3-
'eslint:recommended',
4-
'plugin:@typescript-eslint/recommended',
5-
'plugin:react/recommended',
6-
'plugin:react/jsx-runtime',
7-
'plugin:react-hooks/recommended'
8-
],
9-
plugins: ['jsx-a11y', 'simple-import-sort', '@stylistic'],
10-
parserOptions: {
11-
ecmaFeatures: {
12-
jsx: true
13-
}
14-
},
15-
settings: {
16-
react: {
17-
version: 'detect'
18-
}
19-
},
20-
rules: {
21-
'@stylistic/arrow-parens': 'error',
22-
'@stylistic/arrow-spacing': 'error',
23-
'@stylistic/block-spacing': 'error',
24-
'@stylistic/comma-dangle': ['error', 'always-multiline'],
25-
'@stylistic/eol-last': 'error',
26-
'@stylistic/function-call-spacing': 'error',
27-
'@stylistic/indent': ['error', 2],
28-
'@stylistic/key-spacing': 'error',
29-
'@stylistic/keyword-spacing': 'error',
30-
'@stylistic/max-len': [
31-
'error',
32-
// Do not allow more than 120 characters per line, except for long strings and comments in the same line
33-
{ 'code': 120, 'ignoreComments': true, 'ignoreStrings': true, 'ignoreTemplateLiterals': true },
1+
import eslint from '@eslint/js';
2+
import stylistic from '@stylistic/eslint-plugin';
3+
import pluginJsxA11y from 'eslint-plugin-jsx-a11y';
4+
import react from 'eslint-plugin-react';
5+
import eslintPluginReactHooks from 'eslint-plugin-react-hooks';
6+
import simpleImportSort from 'eslint-plugin-simple-import-sort';
7+
import tseslint from 'typescript-eslint';
8+
9+
export const baseConfig = tseslint.config(
10+
{
11+
extends: [
12+
eslint.configs.recommended,
13+
...tseslint.configs.recommended,
3414
],
35-
'@stylistic/no-trailing-spaces': 'error',
36-
'@stylistic/object-curly-spacing': ['error', 'always'],
37-
'@stylistic/quotes': ['error', 'single'],
38-
'@stylistic/jsx-quotes': ['error', 'prefer-double'],
39-
'@stylistic/rest-spread-spacing': 'error',
40-
'@stylistic/semi': 'error',
41-
'@stylistic/spaced-comment': 'error',
42-
'@stylistic/no-multiple-empty-lines': ['error', { 'max': 1 }],
15+
plugins: {
16+
'@stylistic': stylistic,
17+
'simple-import-sort': simpleImportSort,
18+
},
19+
rules: {
20+
'@stylistic/arrow-parens': 'error',
21+
'@stylistic/arrow-spacing': 'error',
22+
'@stylistic/block-spacing': 'error',
23+
'@stylistic/comma-dangle': ['error', 'always-multiline'],
24+
'@stylistic/eol-last': 'error',
25+
'@stylistic/function-call-spacing': 'error',
26+
'@stylistic/indent': ['error', 2],
27+
'@stylistic/key-spacing': 'error',
28+
'@stylistic/keyword-spacing': 'error',
29+
'@stylistic/max-len': [
30+
'error',
31+
// Do not allow more than 120 characters per line, except for long strings and comments in the same line
32+
{ 'code': 120, 'ignoreComments': true, 'ignoreStrings': true, 'ignoreTemplateLiterals': true },
33+
],
34+
'@stylistic/no-trailing-spaces': 'error',
35+
'@stylistic/object-curly-spacing': ['error', 'always'],
36+
'@stylistic/quotes': ['error', 'single'],
37+
'@stylistic/jsx-quotes': ['error', 'prefer-double'],
38+
'@stylistic/rest-spread-spacing': 'error',
39+
'@stylistic/semi': 'error',
40+
'@stylistic/spaced-comment': 'error',
41+
'@stylistic/no-multiple-empty-lines': ['error', { 'max': 1 }],
4342

44-
'@typescript-eslint/consistent-type-imports': 'error',
43+
'@typescript-eslint/consistent-type-imports': 'error',
4544

46-
'simple-import-sort/imports': ['error', {
47-
'groups': [
48-
// First external imports, then local imports, then styles imports
49-
['^', '^\\.', '\\.s?css$']
50-
]
51-
}],
52-
'no-restricted-exports': ['error', {
53-
'restrictDefaultExports': {
54-
'direct': true,
55-
'named': true,
56-
'defaultFrom': true,
57-
'namedFrom': true,
58-
'namespaceFrom': true
59-
}
60-
}],
45+
'simple-import-sort/imports': ['error', {
46+
'groups': [
47+
// First external imports, then local imports, then styles imports
48+
['^', '^\\.', '\\.s?css$']
49+
]
50+
}],
51+
'no-restricted-exports': ['error', {
52+
'restrictDefaultExports': {
53+
'direct': true,
54+
'named': true,
55+
'defaultFrom': true,
56+
'namedFrom': true,
57+
'namespaceFrom': true
58+
}
59+
}],
6160

62-
// Disabled rules from presets
63-
'react/display-name': ['off', { 'ignoreTranspilerName': false }],
64-
'react/prop-types': 'off',
65-
'@typescript-eslint/ban-types': 'off',
66-
'@typescript-eslint/no-explicit-any': 'off'
61+
// Disabled rules from presets
62+
'@typescript-eslint/ban-types': 'off',
63+
'@typescript-eslint/no-explicit-any': 'off',
64+
},
65+
},
66+
{
67+
files: ['*.test.*', '*.spec.*'],
68+
rules: {
69+
'prefer-promise-reject-errors': 'off',
70+
'no-param-reassign': 'off',
71+
'@typescript-eslint/no-shadow': 'off',
72+
},
6773
},
68-
overrides: [
69-
{
70-
files: ['*.test.*', '*.spec.*'],
71-
rules: {
72-
'prefer-promise-reject-errors': 'off',
73-
'no-param-reassign': 'off',
74-
'react/no-children-prop': 'off',
75-
'@typescript-eslint/no-shadow': 'off'
74+
);
75+
76+
export const reactConfig = tseslint.config(
77+
{
78+
plugins: {
79+
'jsx-a11y': pluginJsxA11y,
80+
react,
81+
'react-hooks': eslintPluginReactHooks,
82+
},
83+
languageOptions: {
84+
parserOptions: {
85+
ecmaFeatures: {
86+
jsx: true,
87+
},
88+
},
89+
},
90+
settings: {
91+
react: {
92+
version: 'detect'
7693
}
77-
}
78-
]
79-
};
94+
},
95+
rules: {
96+
...pluginJsxA11y.configs.recommended.rules,
97+
...eslintPluginReactHooks.configs.recommended.rules,
98+
99+
// Disabled rules from presets
100+
'react/display-name': ['off', { 'ignoreTranspilerName': false }],
101+
'react/prop-types': 'off',
102+
},
103+
},
104+
{
105+
files: ['*.test.*', '*.spec.*'],
106+
rules: {
107+
'react/no-children-prop': 'off',
108+
},
109+
},
110+
);
111+
112+
export default tseslint.config(
113+
...baseConfig,
114+
...reactConfig,
115+
);

0 commit comments

Comments
 (0)