@vllnt/eslint-config 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +237 -0
- package/flat/base.js +25 -0
- package/flat/boundaries.js +5 -0
- package/flat/convex-plugin.js +34 -0
- package/flat/convex-rules/_utils.js +71 -0
- package/flat/convex-rules/namespace-separation.js +90 -0
- package/flat/convex-rules/no-bare-v-any.js +61 -0
- package/flat/convex-rules/no-filter-on-query.js +85 -0
- package/flat/convex-rules/no-query-in-loop.js +114 -0
- package/flat/convex-rules/require-returns-validator.js +60 -0
- package/flat/convex-rules/snake-case-filenames.js +78 -0
- package/flat/convex-rules/standard-filenames.js +62 -0
- package/flat/convex.js +90 -0
- package/flat/core/boundaries.js +13 -0
- package/flat/core/format.js +21 -0
- package/flat/core/good-practices.js +58 -0
- package/flat/core/imports.js +33 -0
- package/flat/core/react.js +80 -0
- package/flat/core/typescript.js +140 -0
- package/flat/core/unicorn.js +165 -0
- package/flat/index.js +7 -0
- package/flat/nextjs.js +83 -0
- package/flat/nodejs.js +31 -0
- package/flat/react.js +36 -0
- package/flat/turbo.js +14 -0
- package/package.json +76 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rule: no-query-in-loop
|
|
3
|
+
* Flags ctx.db.query(), ctx.db.get(), and ctx.runQuery() inside loop bodies.
|
|
4
|
+
* These cause N+1 query performance issues. Use Promise.all() with .map() instead.
|
|
5
|
+
*
|
|
6
|
+
* NOT flagged:
|
|
7
|
+
* - Promise.all(items.map(id => ctx.db.get(id))) — .map() creates a function boundary
|
|
8
|
+
* - for (const x of await ctx.db.query(...).take(500)) — query is the iterable, not in the body
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const LOOP_STATEMENT_TYPES = new Set([
|
|
12
|
+
'ForStatement',
|
|
13
|
+
'WhileStatement',
|
|
14
|
+
'ForOfStatement',
|
|
15
|
+
'ForInStatement',
|
|
16
|
+
'DoWhileStatement',
|
|
17
|
+
])
|
|
18
|
+
|
|
19
|
+
const FUNCTION_BOUNDARY_TYPES = new Set([
|
|
20
|
+
'FunctionDeclaration',
|
|
21
|
+
'FunctionExpression',
|
|
22
|
+
'ArrowFunctionExpression',
|
|
23
|
+
])
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @param {import("estree").CallExpression} node
|
|
27
|
+
* @returns {boolean}
|
|
28
|
+
*/
|
|
29
|
+
function isConvexDbCall(node) {
|
|
30
|
+
const { callee } = node
|
|
31
|
+
|
|
32
|
+
if (
|
|
33
|
+
callee.type === 'MemberExpression' &&
|
|
34
|
+
!callee.computed &&
|
|
35
|
+
callee.object.type === 'Identifier' &&
|
|
36
|
+
callee.object.name === 'ctx' &&
|
|
37
|
+
callee.property.type === 'Identifier' &&
|
|
38
|
+
callee.property.name === 'runQuery'
|
|
39
|
+
) {
|
|
40
|
+
return true
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (
|
|
44
|
+
callee.type === 'MemberExpression' &&
|
|
45
|
+
!callee.computed &&
|
|
46
|
+
callee.object.type === 'MemberExpression' &&
|
|
47
|
+
!callee.object.computed &&
|
|
48
|
+
callee.object.object.type === 'Identifier' &&
|
|
49
|
+
callee.object.object.name === 'ctx' &&
|
|
50
|
+
callee.object.property.type === 'Identifier' &&
|
|
51
|
+
callee.object.property.name === 'db' &&
|
|
52
|
+
callee.property.type === 'Identifier' &&
|
|
53
|
+
(callee.property.name === 'query' || callee.property.name === 'get')
|
|
54
|
+
) {
|
|
55
|
+
return true
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return false
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* @param {import("eslint").Rule.Node} node
|
|
63
|
+
* @returns {boolean}
|
|
64
|
+
*/
|
|
65
|
+
function isInsideLoopBody(node) {
|
|
66
|
+
let current = node
|
|
67
|
+
while (current.parent) {
|
|
68
|
+
const parent = current.parent
|
|
69
|
+
|
|
70
|
+
if (FUNCTION_BOUNDARY_TYPES.has(parent.type)) {
|
|
71
|
+
return false
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (LOOP_STATEMENT_TYPES.has(parent.type)) {
|
|
75
|
+
return parent.body === current
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
current = parent
|
|
79
|
+
}
|
|
80
|
+
return false
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** @type {import("eslint").Rule.RuleModule} */
|
|
84
|
+
const rule = {
|
|
85
|
+
meta: {
|
|
86
|
+
type: 'problem',
|
|
87
|
+
docs: {
|
|
88
|
+
description:
|
|
89
|
+
'Prevent N+1 queries by disallowing ctx.db.query/get/runQuery inside loop bodies',
|
|
90
|
+
},
|
|
91
|
+
messages: {
|
|
92
|
+
noQueryInLoop:
|
|
93
|
+
'Database query/get inside a loop creates N+1 performance issues. Use Promise.all() with .map() for batch fetching.',
|
|
94
|
+
},
|
|
95
|
+
schema: [],
|
|
96
|
+
},
|
|
97
|
+
|
|
98
|
+
create(context) {
|
|
99
|
+
return {
|
|
100
|
+
CallExpression(node) {
|
|
101
|
+
if (!isConvexDbCall(node)) return
|
|
102
|
+
|
|
103
|
+
if (isInsideLoopBody(node)) {
|
|
104
|
+
context.report({
|
|
105
|
+
node,
|
|
106
|
+
messageId: 'noQueryInLoop',
|
|
107
|
+
})
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export default rule
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rule: require-returns-validator
|
|
3
|
+
* All Convex query/mutation/action factory calls must include a `returns` property
|
|
4
|
+
* in their configuration object.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { getConvexFactory } from './_utils.js'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @param {import("estree").ObjectExpression} objNode
|
|
11
|
+
* @param {string} keyName
|
|
12
|
+
* @returns {boolean}
|
|
13
|
+
*/
|
|
14
|
+
function hasProperty(objNode, keyName) {
|
|
15
|
+
return objNode.properties.some(
|
|
16
|
+
(prop) =>
|
|
17
|
+
prop.type === 'Property' &&
|
|
18
|
+
!prop.computed &&
|
|
19
|
+
((prop.key.type === 'Identifier' && prop.key.name === keyName) ||
|
|
20
|
+
(prop.key.type === 'Literal' && prop.key.value === keyName)),
|
|
21
|
+
)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** @type {import("eslint").Rule.RuleModule} */
|
|
25
|
+
const rule = {
|
|
26
|
+
meta: {
|
|
27
|
+
type: 'problem',
|
|
28
|
+
docs: {
|
|
29
|
+
description:
|
|
30
|
+
'All Convex factory functions must include a `returns` validator in their config object',
|
|
31
|
+
},
|
|
32
|
+
messages: {
|
|
33
|
+
missingReturns:
|
|
34
|
+
'Convex {{factoryType}}() must have a `returns` validator. Add `returns: v.null()` or the appropriate validator.',
|
|
35
|
+
},
|
|
36
|
+
schema: [],
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
create(context) {
|
|
40
|
+
return {
|
|
41
|
+
CallExpression(node) {
|
|
42
|
+
const factory = getConvexFactory(node)
|
|
43
|
+
if (!factory) return
|
|
44
|
+
|
|
45
|
+
const configArg = node.arguments[0]
|
|
46
|
+
if (!configArg || configArg.type !== 'ObjectExpression') return
|
|
47
|
+
|
|
48
|
+
if (!hasProperty(configArg, 'returns')) {
|
|
49
|
+
context.report({
|
|
50
|
+
node,
|
|
51
|
+
messageId: 'missingReturns',
|
|
52
|
+
data: { factoryType: factory.factoryType },
|
|
53
|
+
})
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export default rule
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rule: snake-case-filenames
|
|
3
|
+
* Files in convex/ must use snake_case naming (underscores, not hyphens).
|
|
4
|
+
* Reports once per file on the Program node.
|
|
5
|
+
*
|
|
6
|
+
* Exempt: _generated/, uppercase-starting names, non-TS files.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { getFilename, getBasenameNoExt } from './_utils.js'
|
|
10
|
+
|
|
11
|
+
const SNAKE_CASE_RE = /^[a-z][a-z0-9_]*$/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @param {string} name
|
|
15
|
+
* @returns {string}
|
|
16
|
+
*/
|
|
17
|
+
function suggest(name) {
|
|
18
|
+
return name.replaceAll('-', '_')
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** @type {import("eslint").Rule.RuleModule} */
|
|
22
|
+
const rule = {
|
|
23
|
+
meta: {
|
|
24
|
+
type: 'suggestion',
|
|
25
|
+
docs: {
|
|
26
|
+
description:
|
|
27
|
+
'Files in convex/ must use snake_case naming (no hyphens)',
|
|
28
|
+
},
|
|
29
|
+
fixable: null,
|
|
30
|
+
hasSuggestions: true,
|
|
31
|
+
messages: {
|
|
32
|
+
notSnakeCase:
|
|
33
|
+
'File "{{filename}}" must use snake_case naming in convex/. Rename to "{{suggested}}".',
|
|
34
|
+
},
|
|
35
|
+
schema: [],
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
create(context) {
|
|
39
|
+
const filePath = getFilename(context)
|
|
40
|
+
|
|
41
|
+
if (!filePath.includes('/convex/')) return {}
|
|
42
|
+
if (filePath.includes('/_generated/')) return {}
|
|
43
|
+
if (!filePath.endsWith('.ts') && !filePath.endsWith('.mjs')) return {}
|
|
44
|
+
|
|
45
|
+
const baseName = getBasenameNoExt(filePath)
|
|
46
|
+
|
|
47
|
+
if (
|
|
48
|
+
baseName.length > 0 &&
|
|
49
|
+
baseName[0] === baseName[0].toUpperCase() &&
|
|
50
|
+
baseName[0] !== baseName[0].toLowerCase()
|
|
51
|
+
) {
|
|
52
|
+
return {}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (SNAKE_CASE_RE.test(baseName)) return {}
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
Program(node) {
|
|
59
|
+
const suggestedName = suggest(baseName)
|
|
60
|
+
const fullBasename = filePath.split('/').pop() ?? filePath
|
|
61
|
+
const extMatch = fullBasename.match(/(\.[^.]+)$/)
|
|
62
|
+
const ext = extMatch ? extMatch[1] : ''
|
|
63
|
+
const suggestedFull = suggestedName + ext
|
|
64
|
+
|
|
65
|
+
context.report({
|
|
66
|
+
node,
|
|
67
|
+
messageId: 'notSnakeCase',
|
|
68
|
+
data: {
|
|
69
|
+
filename: fullBasename,
|
|
70
|
+
suggested: suggestedFull,
|
|
71
|
+
},
|
|
72
|
+
})
|
|
73
|
+
},
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export default rule
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rule: standard-filenames
|
|
3
|
+
* Convex factory exports (query, mutation, action, etc.) must live in
|
|
4
|
+
* standard-named files: queries.ts, mutations.ts, actions.ts, or internal_mutations.ts.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
STANDARD_CONVEX_FILENAMES,
|
|
9
|
+
getConvexFactory,
|
|
10
|
+
getBasename,
|
|
11
|
+
getFilename,
|
|
12
|
+
} from './_utils.js'
|
|
13
|
+
|
|
14
|
+
/** @type {import("eslint").Rule.RuleModule} */
|
|
15
|
+
const rule = {
|
|
16
|
+
meta: {
|
|
17
|
+
type: 'problem',
|
|
18
|
+
docs: {
|
|
19
|
+
description:
|
|
20
|
+
'Convex factory exports must be in standard-named files (queries.ts, mutations.ts, actions.ts, internal_mutations.ts)',
|
|
21
|
+
},
|
|
22
|
+
messages: {
|
|
23
|
+
wrongFilename:
|
|
24
|
+
'Convex {{factoryType}}() exports must be in a standard-named file (queries.ts, mutations.ts, actions.ts, or internal_mutations.ts). Found in "{{filename}}".',
|
|
25
|
+
},
|
|
26
|
+
schema: [],
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
create(context) {
|
|
30
|
+
const filename = getFilename(context)
|
|
31
|
+
const basename = getBasename(filename)
|
|
32
|
+
|
|
33
|
+
if (STANDARD_CONVEX_FILENAMES.has(basename)) {
|
|
34
|
+
return {}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
ExportNamedDeclaration(node) {
|
|
39
|
+
const decl = node.declaration
|
|
40
|
+
if (!decl || decl.type !== 'VariableDeclaration') return
|
|
41
|
+
|
|
42
|
+
for (const declarator of decl.declarations) {
|
|
43
|
+
const init = declarator.init
|
|
44
|
+
if (!init) continue
|
|
45
|
+
const factory = getConvexFactory(init)
|
|
46
|
+
if (!factory) continue
|
|
47
|
+
|
|
48
|
+
context.report({
|
|
49
|
+
node: declarator,
|
|
50
|
+
messageId: 'wrongFilename',
|
|
51
|
+
data: {
|
|
52
|
+
factoryType: factory.factoryType,
|
|
53
|
+
filename: basename,
|
|
54
|
+
},
|
|
55
|
+
})
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export default rule
|
package/flat/convex.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convex ESLint config — strict backend best practices.
|
|
3
|
+
*
|
|
4
|
+
* Includes: all 4 @convex-dev official rules, 7 custom convex-rules
|
|
5
|
+
* (structure, naming, query optimization, type safety), and
|
|
6
|
+
* explicit-module-boundary-types for Convex functions.
|
|
7
|
+
*
|
|
8
|
+
* @example Standalone
|
|
9
|
+
* import { convex } from '@vllnt/eslint-config/convex'
|
|
10
|
+
* export default [...convex]
|
|
11
|
+
*
|
|
12
|
+
* @example Composed with base (recommended)
|
|
13
|
+
* import { base } from '@vllnt/eslint-config'
|
|
14
|
+
* import { convex } from '@vllnt/eslint-config/convex'
|
|
15
|
+
* export default [...base, ...convex]
|
|
16
|
+
*/
|
|
17
|
+
import tseslint from 'typescript-eslint'
|
|
18
|
+
import convexPlugin from '@convex-dev/eslint-plugin'
|
|
19
|
+
import convexRulesPlugin from './convex-plugin.js'
|
|
20
|
+
|
|
21
|
+
const CONVEX_SOURCE = ['**/convex/**/*.ts']
|
|
22
|
+
const CONVEX_EXCLUDED = [
|
|
23
|
+
'**/convex/_generated/**',
|
|
24
|
+
'**/convex/**/*.test.ts',
|
|
25
|
+
'**/convex/testing/**',
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
export const convex = [
|
|
29
|
+
{
|
|
30
|
+
plugins: {
|
|
31
|
+
'@typescript-eslint': tseslint.plugin,
|
|
32
|
+
'@convex-dev': convexPlugin,
|
|
33
|
+
'convex-rules': convexRulesPlugin,
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
// ── Core rules: all convex source files ───────────────────────────────
|
|
38
|
+
{
|
|
39
|
+
files: CONVEX_SOURCE,
|
|
40
|
+
ignores: CONVEX_EXCLUDED,
|
|
41
|
+
rules: {
|
|
42
|
+
// Official @convex-dev plugin (all 4 rules)
|
|
43
|
+
'@convex-dev/no-old-registered-function-syntax': 'error',
|
|
44
|
+
'@convex-dev/require-args-validator': 'error',
|
|
45
|
+
'@convex-dev/explicit-table-ids': 'error',
|
|
46
|
+
'@convex-dev/import-wrong-runtime': 'error',
|
|
47
|
+
|
|
48
|
+
// Structure
|
|
49
|
+
'convex-rules/standard-filenames': 'error',
|
|
50
|
+
'convex-rules/namespace-separation': 'error',
|
|
51
|
+
'convex-rules/snake-case-filenames': 'error',
|
|
52
|
+
|
|
53
|
+
// Type safety
|
|
54
|
+
'convex-rules/no-bare-v-any': 'error',
|
|
55
|
+
'convex-rules/require-returns-validator': 'error',
|
|
56
|
+
|
|
57
|
+
// Query optimization
|
|
58
|
+
'convex-rules/no-query-in-loop': 'error',
|
|
59
|
+
'convex-rules/no-filter-on-query': 'error',
|
|
60
|
+
|
|
61
|
+
// Explicit return types on Convex functions
|
|
62
|
+
'@typescript-eslint/explicit-module-boundary-types': 'error',
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
// ── Override: config files (exempt from snake_case + boundary types) ──
|
|
67
|
+
{
|
|
68
|
+
files: [
|
|
69
|
+
'**/convex/auth.ts',
|
|
70
|
+
'**/convex/auth.config.ts',
|
|
71
|
+
'**/convex/convex.config.ts',
|
|
72
|
+
],
|
|
73
|
+
rules: {
|
|
74
|
+
'convex-rules/snake-case-filenames': 'off',
|
|
75
|
+
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
|
|
79
|
+
// ── Override: migration files (relaxed structure rules) ───────────────
|
|
80
|
+
{
|
|
81
|
+
files: ['**/convex/migrations/**'],
|
|
82
|
+
rules: {
|
|
83
|
+
'convex-rules/standard-filenames': 'off',
|
|
84
|
+
'convex-rules/namespace-separation': 'off',
|
|
85
|
+
'convex-rules/no-query-in-loop': 'off',
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
]
|
|
89
|
+
|
|
90
|
+
export default convex
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import boundariesPlugin from 'eslint-plugin-boundaries'
|
|
2
|
+
|
|
3
|
+
export const boundariesConfig = {
|
|
4
|
+
plugins: {
|
|
5
|
+
boundaries: boundariesPlugin,
|
|
6
|
+
},
|
|
7
|
+
settings: {
|
|
8
|
+
...boundariesPlugin.configs.recommended.settings,
|
|
9
|
+
},
|
|
10
|
+
rules: {
|
|
11
|
+
...boundariesPlugin.configs.recommended.rules,
|
|
12
|
+
},
|
|
13
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import prettierPlugin from 'eslint-plugin-prettier'
|
|
2
|
+
import perfectionistPlugin from 'eslint-plugin-perfectionist'
|
|
3
|
+
|
|
4
|
+
export const format = {
|
|
5
|
+
plugins: {
|
|
6
|
+
prettier: prettierPlugin,
|
|
7
|
+
perfectionist: perfectionistPlugin,
|
|
8
|
+
},
|
|
9
|
+
rules: {
|
|
10
|
+
'prettier/prettier': 'error',
|
|
11
|
+
'perfectionist/sort-array-includes': ['error', { type: 'natural' }],
|
|
12
|
+
'perfectionist/sort-enums': ['error', { type: 'natural' }],
|
|
13
|
+
'perfectionist/sort-interfaces': ['error', { type: 'natural' }],
|
|
14
|
+
'perfectionist/sort-jsx-props': ['error', { type: 'natural' }],
|
|
15
|
+
'perfectionist/sort-maps': ['error', { type: 'natural' }],
|
|
16
|
+
'perfectionist/sort-named-exports': ['error', { type: 'natural' }],
|
|
17
|
+
'perfectionist/sort-object-types': ['error', { type: 'natural' }],
|
|
18
|
+
'perfectionist/sort-objects': ['error', { type: 'natural' }],
|
|
19
|
+
'perfectionist/sort-union-types': ['error', { type: 'natural' }],
|
|
20
|
+
},
|
|
21
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import functionalPlugin from 'eslint-plugin-functional'
|
|
2
|
+
import writeGoodCommentsPlugin from 'eslint-plugin-write-good-comments'
|
|
3
|
+
|
|
4
|
+
export const goodPractices = {
|
|
5
|
+
plugins: {
|
|
6
|
+
functional: functionalPlugin,
|
|
7
|
+
'write-good-comments': writeGoodCommentsPlugin,
|
|
8
|
+
},
|
|
9
|
+
rules: {
|
|
10
|
+
'no-unreachable-loop': 'error',
|
|
11
|
+
'prefer-const': 'error',
|
|
12
|
+
'no-async-promise-executor': 'error',
|
|
13
|
+
'no-console': ['error', { allow: ['debug', 'error', 'info', 'warn'] }],
|
|
14
|
+
'write-good-comments/write-good-comments': 'error',
|
|
15
|
+
'max-params': ['error', 3],
|
|
16
|
+
'max-lines-per-function': [
|
|
17
|
+
'error',
|
|
18
|
+
{
|
|
19
|
+
max: 30,
|
|
20
|
+
skipBlankLines: true,
|
|
21
|
+
skipComments: true,
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
'no-param-reassign': 'error',
|
|
25
|
+
'max-depth': ['error', 3],
|
|
26
|
+
'functional/no-loop-statements': 'error',
|
|
27
|
+
'functional/functional-parameters': [
|
|
28
|
+
'error',
|
|
29
|
+
{
|
|
30
|
+
allowRestParameter: true,
|
|
31
|
+
allowArgumentsKeyword: false,
|
|
32
|
+
enforceParameterCount: false,
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
'functional/readonly-type': ['error', 'keyword'],
|
|
36
|
+
},
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export const goodPracticesTsx = {
|
|
40
|
+
files: ['**/*.tsx'],
|
|
41
|
+
rules: {
|
|
42
|
+
'max-lines-per-function': [
|
|
43
|
+
'error',
|
|
44
|
+
{
|
|
45
|
+
max: 70,
|
|
46
|
+
skipBlankLines: true,
|
|
47
|
+
skipComments: true,
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
},
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export const goodPracticesTest = {
|
|
54
|
+
files: ['**/*.test.ts', '**/*.spec.ts', '**/*.e2e.ts'],
|
|
55
|
+
rules: {
|
|
56
|
+
'max-lines-per-function': 'off',
|
|
57
|
+
},
|
|
58
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import simpleImportSort from 'eslint-plugin-simple-import-sort'
|
|
2
|
+
|
|
3
|
+
export const imports = {
|
|
4
|
+
plugins: {
|
|
5
|
+
'simple-import-sort': simpleImportSort,
|
|
6
|
+
},
|
|
7
|
+
rules: {
|
|
8
|
+
'sort-imports': 'off',
|
|
9
|
+
'no-duplicate-imports': 'off',
|
|
10
|
+
'@typescript-eslint/consistent-type-imports': [
|
|
11
|
+
'error',
|
|
12
|
+
{
|
|
13
|
+
prefer: 'type-imports',
|
|
14
|
+
fixStyle: 'inline-type-imports',
|
|
15
|
+
},
|
|
16
|
+
],
|
|
17
|
+
'simple-import-sort/imports': [
|
|
18
|
+
'error',
|
|
19
|
+
{
|
|
20
|
+
groups: [
|
|
21
|
+
['^\\u0000'],
|
|
22
|
+
['^react$', '^node:'],
|
|
23
|
+
['^[^.]'],
|
|
24
|
+
|
|
25
|
+
['^@/'],
|
|
26
|
+
['^../'],
|
|
27
|
+
['^./'],
|
|
28
|
+
],
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
'simple-import-sort/exports': 'error',
|
|
32
|
+
},
|
|
33
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import reactPlugin from 'eslint-plugin-react'
|
|
2
|
+
import reactHooksPlugin from 'eslint-plugin-react-hooks'
|
|
3
|
+
import jsxA11yPlugin from 'eslint-plugin-jsx-a11y'
|
|
4
|
+
import cssModulesPlugin from 'eslint-plugin-css-modules'
|
|
5
|
+
|
|
6
|
+
export const reactConfig = {
|
|
7
|
+
plugins: {
|
|
8
|
+
react: reactPlugin,
|
|
9
|
+
'react-hooks': reactHooksPlugin,
|
|
10
|
+
'jsx-a11y': jsxA11yPlugin,
|
|
11
|
+
'css-modules': cssModulesPlugin,
|
|
12
|
+
},
|
|
13
|
+
settings: {
|
|
14
|
+
react: {
|
|
15
|
+
version: 'detect',
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
rules: {
|
|
19
|
+
...reactPlugin.configs.recommended.rules,
|
|
20
|
+
...reactPlugin.configs['jsx-runtime'].rules,
|
|
21
|
+
...jsxA11yPlugin.configs.recommended.rules,
|
|
22
|
+
'jsx-a11y/label-has-associated-control': [
|
|
23
|
+
'error',
|
|
24
|
+
{
|
|
25
|
+
assert: 'either',
|
|
26
|
+
depth: 3,
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
'react/display-name': 'error',
|
|
30
|
+
'react/prop-types': 'off',
|
|
31
|
+
'react/react-in-jsx-scope': 'off',
|
|
32
|
+
'react/boolean-prop-naming': 'error',
|
|
33
|
+
'react/button-has-type': 'error',
|
|
34
|
+
'react/hook-use-state': 'error',
|
|
35
|
+
'react/jsx-child-element-spacing': 'error',
|
|
36
|
+
'react/jsx-closing-bracket-location': 'error',
|
|
37
|
+
'react/jsx-closing-tag-location': 'error',
|
|
38
|
+
'react/jsx-curly-brace-presence': [
|
|
39
|
+
'error',
|
|
40
|
+
{ props: 'never', children: 'never', propElementValues: 'always' },
|
|
41
|
+
],
|
|
42
|
+
'react/jsx-curly-newline': 'error',
|
|
43
|
+
'react/jsx-curly-spacing': 'error',
|
|
44
|
+
'react/jsx-equals-spacing': 'error',
|
|
45
|
+
'react/jsx-handler-names': 'error',
|
|
46
|
+
'react/jsx-no-constructed-context-values': 'error',
|
|
47
|
+
'react/jsx-no-leaked-render': 'error',
|
|
48
|
+
'react/jsx-no-useless-fragment': 'error',
|
|
49
|
+
'react/jsx-pascal-case': ['error', { ignore: [], allowNamespace: true }],
|
|
50
|
+
'react/jsx-props-no-multi-spaces': 'error',
|
|
51
|
+
'react/jsx-wrap-multilines': [
|
|
52
|
+
'error',
|
|
53
|
+
{
|
|
54
|
+
declaration: 'parens-new-line',
|
|
55
|
+
assignment: 'parens-new-line',
|
|
56
|
+
return: 'parens-new-line',
|
|
57
|
+
arrow: 'parens-new-line',
|
|
58
|
+
condition: 'parens-new-line',
|
|
59
|
+
logical: 'parens-new-line',
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
'react/no-invalid-html-attribute': 'error',
|
|
63
|
+
'react/no-this-in-sfc': 'error',
|
|
64
|
+
'react/no-unstable-nested-components': 'error',
|
|
65
|
+
'react/prefer-stateless-function': 'error',
|
|
66
|
+
'react/self-closing-comp': 'error',
|
|
67
|
+
'react/style-prop-object': 'error',
|
|
68
|
+
'react/void-dom-elements-no-children': 'error',
|
|
69
|
+
'@typescript-eslint/restrict-template-expressions': [
|
|
70
|
+
'error',
|
|
71
|
+
{ allowNumber: true },
|
|
72
|
+
],
|
|
73
|
+
...Object.fromEntries(
|
|
74
|
+
Object.entries(reactHooksPlugin.configs['recommended-latest'].rules).map(
|
|
75
|
+
([rule, config]) => [rule, config === 'warn' ? 'error' : config],
|
|
76
|
+
),
|
|
77
|
+
),
|
|
78
|
+
'css-modules/no-unused-class': 'off',
|
|
79
|
+
},
|
|
80
|
+
}
|