Repository navigation
Expand file tree
/
Copy patheslint.config.js
More file actions
165 lines (151 loc) · 4.04 KB
/
Copy patheslint.config.js
File metadata and controls
165 lines (151 loc) · 4.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
// @ts-check
import * as path from 'node:path'
import { fileURLToPath } from 'node:url'
import eslint from '@eslint/js'
import { includeIgnoreFile } from '@eslint/compat'
import prettier from 'eslint-config-prettier'
import node from 'eslint-plugin-n'
import vitest from '@vitest/eslint-plugin'
import tseslint from 'typescript-eslint'
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
export default tseslint.config(
// Global rules and configuration
includeIgnoreFile(path.resolve(__dirname, '.gitignore')),
{
linterOptions: {
reportUnusedDisableDirectives: true,
},
},
// JavaScript-specific rules
eslint.configs.recommended,
// Typescript-specific rules
tseslint.configs.strictTypeChecked,
tseslint.configs.stylisticTypeChecked,
{
languageOptions: {
parserOptions: {
projectService: true,
tsconfigRootDir: __dirname,
},
},
},
{
files: ['**/*.?(c|m)js?(x)'],
...tseslint.configs.disableTypeChecked,
},
node.configs['flat/recommended'],
{
rules: {
'n/no-extraneous-import': 'off',
'n/no-extraneous-require': 'off',
'n/no-missing-import': 'off',
'n/no-missing-require': 'off',
'n/no-unpublished-import': 'off',
'n/no-unpublished-require': 'off',
},
},
// Project-specific rules
{
ignores: ['.github/styles/', '**/__fixtures__/', 'functions-templates/**', 'site/**'],
},
{
rules: {
// We use these globals even though they're technically unstable features on our minimum
// supported node version.
'n/no-unsupported-features/node-builtins': [
'error',
{
ignores: ['FormData', 'ReadableStream', 'Response', 'Request', 'fetch', 'fs/promises.cp'],
},
],
},
},
{
files: ['**/*.?(c|m)ts?(x)'],
rules: {
// `interface` and `type` have different use cases, allow both
'@typescript-eslint/consistent-type-definitions': 'off',
// Ignore underscore-prefixed unused variables (mirrors tsc behavior)
'@typescript-eslint/no-unused-vars': [
'error',
{
args: 'all',
argsIgnorePattern: '^_',
caughtErrors: 'all',
caughtErrorsIgnorePattern: '^_',
destructuredArrayIgnorePattern: '^_',
ignoreRestSiblings: true,
varsIgnorePattern: '^_',
},
],
},
},
{
rules: {
'no-restricted-imports': [
'error',
{
paths: [
{
name: 'node:process',
importNames: ['cwd'],
message: 'Use `command.workingDir` instead.',
},
{
name: 'process',
importNames: ['cwd'],
message: 'Use `command.workingDir` instead.',
},
{
name: 'chalk',
message:
'Use the safe chalk import that handles colors for json output: `import { chalk } from "src/utils/command-helpers.js"`',
},
],
},
],
'no-restricted-properties': [
'error',
{
object: 'process',
property: 'cwd',
message: '`process.cwd` is not permitted; use `command.workingDir` instead.',
},
],
},
},
{
files: ['src/lib/completion/script.ts'],
rules: {
// tabtab runs this file directly, so the shebang is intentional
'n/hashbang': 'off',
},
},
// Tests
{
files: ['**/*.test.?(c|m)[jt]s?(x)'],
plugins: { vitest },
rules: {
...vitest.configs.recommended.rules,
'vitest/expect-expect': [
'error',
{
assertFunctionNames: [
// Defaults
'assert',
'expect',
// Fix issue where text-context-specific `expect()` calls trigger false positive
't.expect',
'ctx.expect',
'context.expect',
// Custom assertion functions
'assertNetlifyToml',
],
},
],
},
},
// Must be last
prettier,
)