Skip to content

Commit e848b6f

Browse files
committed
Define separate entry points for base and react configs
1 parent d02a1c6 commit e848b6f

File tree

5 files changed

+165
-121
lines changed

5 files changed

+165
-121
lines changed

README.md

+16-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Coding standard used by Shlink JavaScript projects.
99

1010
This library includes two ESLint configurations, the base one (which includes eslint and typescript recommended rules), and the react-specific one (which includes JSX accessibility, react and react hooks recommended rules).
1111

12-
Default export includes both:
12+
Then there's a third one on the default entry point which includes both:
1313

1414
```js
1515
// eslint.config.js
@@ -27,7 +27,7 @@ If the project does not use React, you can just use the base config:
2727

2828
```js
2929
// eslint.config.js
30-
import { baseConfig } from '@shlinkio/eslint-config-js-coding-standard';
30+
import baseConfig from '@shlinkio/eslint-config-js-coding-standard/base';
3131

3232
export default [
3333
...baseConfig,
@@ -36,3 +36,17 @@ export default [
3636
}
3737
];
3838
```
39+
40+
If you need to access the react rules individually, use the `/react` entry point:
41+
42+
```js
43+
// eslint.config.js
44+
import reactConfig from '@shlinkio/eslint-config-js-coding-standard/react';
45+
46+
export default [
47+
...reactConfig,
48+
{
49+
// Other rules...
50+
}
51+
];
52+
```

base.js

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import tseslint from 'typescript-eslint';
2+
import importPlugin from 'eslint-plugin-import';
3+
import stylistic from '@stylistic/eslint-plugin';
4+
import simpleImportSort from 'eslint-plugin-simple-import-sort';
5+
6+
const baseConfig = tseslint.config(
7+
eslint.configs.recommended,
8+
...tseslint.configs.recommended,
9+
importPlugin.flatConfigs.recommended,
10+
{
11+
plugins: {
12+
'@stylistic': stylistic,
13+
'simple-import-sort': simpleImportSort,
14+
},
15+
rules: {
16+
'@stylistic/arrow-parens': 'error',
17+
'@stylistic/arrow-spacing': 'error',
18+
'@stylistic/block-spacing': 'error',
19+
'@stylistic/comma-dangle': ['error', 'always-multiline'],
20+
'@stylistic/eol-last': 'error',
21+
'@stylistic/function-call-spacing': 'error',
22+
'@stylistic/indent': ['error', 2],
23+
'@stylistic/key-spacing': 'error',
24+
'@stylistic/keyword-spacing': 'error',
25+
'@stylistic/max-len': [
26+
'error',
27+
// Do not allow more than 120 characters per line, except for long strings and comments in the same line
28+
{ 'code': 120, 'ignoreComments': true, 'ignoreStrings': true, 'ignoreTemplateLiterals': true },
29+
],
30+
'@stylistic/no-trailing-spaces': 'error',
31+
'@stylistic/object-curly-spacing': ['error', 'always'],
32+
'@stylistic/quotes': ['error', 'single'],
33+
'@stylistic/jsx-quotes': ['error', 'prefer-double'],
34+
'@stylistic/rest-spread-spacing': 'error',
35+
'@stylistic/semi': 'error',
36+
'@stylistic/spaced-comment': 'error',
37+
'@stylistic/no-multiple-empty-lines': ['error', { 'max': 1 }],
38+
39+
'@typescript-eslint/consistent-type-imports': 'error',
40+
41+
'simple-import-sort/imports': ['error', {
42+
'groups': [
43+
// First external imports, then local imports, then styles imports
44+
['^', '^\\.', '\\.s?css$']
45+
]
46+
}],
47+
'no-restricted-exports': ['error', {
48+
'restrictDefaultExports': {
49+
'direct': true,
50+
'named': true,
51+
'defaultFrom': true,
52+
'namedFrom': true,
53+
'namespaceFrom': true
54+
}
55+
}],
56+
57+
'import/no-duplicates': 'error',
58+
59+
// Disabled rules from presets
60+
'@typescript-eslint/ban-types': 'off',
61+
'@typescript-eslint/no-explicit-any': 'off',
62+
'import/no-unresolved': 'off',
63+
},
64+
},
65+
{
66+
files: ['*.test.*', '*.spec.*'],
67+
rules: {
68+
'prefer-promise-reject-errors': 'off',
69+
'no-param-reassign': 'off',
70+
'@typescript-eslint/no-shadow': 'off',
71+
},
72+
},
73+
);
74+
75+
export default baseConfig;

index.js

+2-117
Original file line numberDiff line numberDiff line change
@@ -1,120 +1,5 @@
1-
import eslint from '@eslint/js';
2-
import stylistic from '@stylistic/eslint-plugin';
3-
import importPlugin from 'eslint-plugin-import';
4-
import pluginJsxA11y from 'eslint-plugin-jsx-a11y';
5-
import react from 'eslint-plugin-react';
6-
import reactCompiler from 'eslint-plugin-react-compiler';
7-
import reactHooks from 'eslint-plugin-react-hooks';
8-
import simpleImportSort from 'eslint-plugin-simple-import-sort';
9-
import tseslint from 'typescript-eslint';
10-
11-
export const baseConfig = tseslint.config(
12-
eslint.configs.recommended,
13-
...tseslint.configs.recommended,
14-
importPlugin.flatConfigs.recommended,
15-
{
16-
plugins: {
17-
'@stylistic': stylistic,
18-
'simple-import-sort': simpleImportSort,
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 },
34-
],
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 }],
43-
44-
'@typescript-eslint/consistent-type-imports': 'error',
45-
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-
}],
61-
62-
'import/no-duplicates': 'error',
63-
64-
// Disabled rules from presets
65-
'@typescript-eslint/ban-types': 'off',
66-
'@typescript-eslint/no-explicit-any': 'off',
67-
'import/no-unresolved': 'off',
68-
},
69-
},
70-
{
71-
files: ['*.test.*', '*.spec.*'],
72-
rules: {
73-
'prefer-promise-reject-errors': 'off',
74-
'no-param-reassign': 'off',
75-
'@typescript-eslint/no-shadow': 'off',
76-
},
77-
},
78-
);
79-
80-
export const reactConfig = [
81-
react.configs.flat.recommended,
82-
react.configs.flat['jsx-runtime'],
83-
pluginJsxA11y.flatConfigs.recommended,
84-
reactCompiler.configs.recommended,
85-
{
86-
plugins: {
87-
'react-hooks': reactHooks,
88-
},
89-
languageOptions: {
90-
parserOptions: {
91-
ecmaFeatures: {
92-
jsx: true,
93-
},
94-
},
95-
},
96-
settings: {
97-
react: {
98-
version: 'detect'
99-
}
100-
},
101-
rules: {
102-
'react/jsx-tag-spacing': ['error', { beforeClosing: 'never' }],
103-
'react-hooks/rules-of-hooks': 'error',
104-
'react-hooks/exhaustive-deps': 'error',
105-
106-
// Disabled rules from presets
107-
'react/display-name': ['off', { 'ignoreTranspilerName': false }],
108-
'react/prop-types': 'off',
109-
},
110-
},
111-
{
112-
files: ['*.test.*', '*.spec.*'],
113-
rules: {
114-
'react/no-children-prop': 'off',
115-
},
116-
},
117-
];
1+
import baseConfig from './base.js';
2+
import reactConfig from './react.js';
1183

1194
export default [
1205
...baseConfig,

package.json

+27-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
11
{
22
"name": "@shlinkio/eslint-config-js-coding-standard",
33
"description": "Coding standard used by shlink JavaScript projects",
4-
"main": "dist/index.js",
54
"type": "module",
5+
"main": "dist/index.js",
6+
"exports": {
7+
".": {
8+
"import": "./dist/index.js"
9+
},
10+
"./base": {
11+
"import": "./dist/base.js"
12+
},
13+
"./react": {
14+
"import": "./dist/react.js"
15+
}
16+
},
617
"repository": {
718
"type": "git",
819
"url": "git+https://github.com/shlinkio/js-coding-standard.git"
@@ -20,7 +31,7 @@
2031
},
2132
"homepage": "https://github.com/shlinkio/js-coding-standard",
2233
"scripts": {
23-
"build": "mkdir -p dist && rm -rf dist/* && cp index.js dist"
34+
"build": "mkdir -p dist && rm -rf dist/* && cp *.js dist"
2435
},
2536
"peerDependencies": {
2637
"@stylistic/eslint-plugin": ">=4.2.0",
@@ -33,6 +44,20 @@
3344
"eslint-plugin-simple-import-sort": "^12.1.0",
3445
"typescript-eslint": "^8.28"
3546
},
47+
"peerDependenciesMeta": {
48+
"eslint-plugin-jsx-a11y": {
49+
"optional": true
50+
},
51+
"eslint-plugin-react": {
52+
"optional": true
53+
},
54+
"eslint-plugin-react-compiler": {
55+
"optional": true
56+
},
57+
"eslint-plugin-react-hooks": {
58+
"optional": true
59+
}
60+
},
3661
"devDependencies": {
3762
"typescript": "^5.8.2"
3863
},

react.js

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import react from 'eslint-plugin-react';
2+
import pluginJsxA11y from 'eslint-plugin-jsx-a11y';
3+
import reactCompiler from 'eslint-plugin-react-compiler';
4+
import reactHooks from 'eslint-plugin-react-hooks';
5+
6+
const reactConfig = [
7+
react.configs.flat.recommended,
8+
react.configs.flat['jsx-runtime'],
9+
pluginJsxA11y.flatConfigs.recommended,
10+
reactCompiler.configs.recommended,
11+
{
12+
plugins: {
13+
'react-hooks': reactHooks,
14+
},
15+
languageOptions: {
16+
parserOptions: {
17+
ecmaFeatures: {
18+
jsx: true,
19+
},
20+
},
21+
},
22+
settings: {
23+
react: {
24+
version: 'detect'
25+
}
26+
},
27+
rules: {
28+
'react/jsx-tag-spacing': ['error', { beforeClosing: 'never' }],
29+
'react-hooks/rules-of-hooks': 'error',
30+
'react-hooks/exhaustive-deps': 'error',
31+
32+
// Disabled rules from presets
33+
'react/display-name': ['off', { 'ignoreTranspilerName': false }],
34+
'react/prop-types': 'off',
35+
},
36+
},
37+
{
38+
files: ['*.test.*', '*.spec.*'],
39+
rules: {
40+
'react/no-children-prop': 'off',
41+
},
42+
},
43+
];
44+
45+
export default reactConfig;

0 commit comments

Comments
 (0)