-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy patheslint.config.mjs
More file actions
234 lines (222 loc) · 7.03 KB
/
Copy patheslint.config.mjs
File metadata and controls
234 lines (222 loc) · 7.03 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';
import globals from 'globals';
import nodePlugin from 'eslint-plugin-n';
import prettierPlugin from 'eslint-plugin-prettier';
import prettierRecommended from 'eslint-plugin-prettier/recommended';
import yalhPlugin from 'eslint-plugin-yet-another-license-header';
const defaultLicense = `
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
`;
// This matches `defaultLicense`, but allows additional Copyright holders
// either on the same line:
// Copyright The OpenTelemetry Authors, <someone>, <another someone>
// and/or on subsequent lines:
// Copyright The OpenTelemetry Authors
// Copyright <someone>
// Copyright <another someone>
const licensePattern =
/^\/\*\n \* Copyright The OpenTelemetry Authors(?:, [^\n]+)*\n(?: \* Copyright [^\n]+\n)* \* SPDX-License-Identifier: Apache-2.0\n \*\/$/;
export default tseslint.config(
{
ignores: [
'**/.nx/**',
'**/build/**',
'**/coverage/**',
'**/dist/**',
'**/node_modules/**',
'**/protos/**',
'**/.tmp/**',
'docs/**',
// tsd-style negative type-check fixtures, intentionally outside tsconfig.
'experimental/packages/configuration/test/fixtures/types/**',
'experimental/packages/otlp-transformer/src/generated/**',
'experimental/packages/otlp-transformer/test/generated/**',
// protobuf-ts generated test fixtures (buf generate output, gitignored).
'experimental/packages/opentelemetry-instrumentation-grpc/test/proto/**',
// protobuf-generated example sources.
'examples/grpc-js/helloworld_pb.js',
'examples/grpc-js/helloworld_grpc_pb.js',
'semantic-conventions/src/experimental_attributes.ts',
'semantic-conventions/src/experimental_metrics.ts',
'semantic-conventions/src/stable_attributes.ts',
'semantic-conventions/src/stable_metrics.ts',
],
},
// Files we lint. The legacy setup ran `eslint . --ext .ts` per package and
// explicit JS/MJS in examples + e2e-tests + integration-tests/api. We
// mirror that here so unrelated `.js` files (karma configs, etc.) stay
// untouched.
{
files: [
'**/*.ts',
'examples/**/*.{js,mjs,cjs}',
'experimental/examples/**/*.{js,mjs,cjs}',
'e2e-tests/**/*.{js,mjs,cjs}',
'integration-tests/**/*.{js,cjs}',
],
plugins: {
n: nodePlugin,
prettier: prettierPlugin,
'yet-another-license-header': yalhPlugin,
},
extends: [eslint.configs.recommended, prettierRecommended],
languageOptions: {
ecmaVersion: 2022,
sourceType: 'module',
globals: {
...globals.node,
...globals.browser,
...globals.mocha,
},
},
rules: {
quotes: ['error', 'single', { avoidEscape: true }],
eqeqeq: ['error', 'smart'],
'prefer-rest-params': 'off',
'no-console': 'error',
'no-shadow': 'off',
'n/no-deprecated-api': 'warn',
'yet-another-license-header/header': [
'error',
{
header: defaultLicense,
allowedHeaderPatterns: [licensePattern],
},
],
},
},
// TypeScript files: enable the TS parser and TS-specific rules.
{
files: ['**/*.ts'],
extends: [...tseslint.configs.recommended],
languageOptions: {
parser: tseslint.parser,
parserOptions: {
projectService: true,
},
},
rules: {
'@typescript-eslint/no-floating-promises': 'error',
'@typescript-eslint/no-this-alias': 'off',
'@typescript-eslint/naming-convention': [
'error',
{
selector: 'memberLike',
modifiers: ['private', 'protected'],
format: ['camelCase'],
leadingUnderscore: 'require',
},
],
'@typescript-eslint/consistent-type-imports': [
'error',
{
prefer: 'type-imports',
fixStyle: 'separate-type-imports',
},
],
'@typescript-eslint/no-unused-vars': [
'error',
{ argsIgnorePattern: '^_', args: 'after-used' },
],
'@typescript-eslint/no-inferrable-types': [
'error',
{ ignoreProperties: true },
],
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-unsafe-function-type': 'warn',
'@typescript-eslint/no-shadow': 'warn',
'@typescript-eslint/parameter-properties': 'error',
'no-restricted-syntax': ['error', 'ExportAllDeclaration'],
'prefer-rest-params': 'off',
},
},
// Test sources: relax most rules, mirroring the legacy `test/**/*.ts` override.
{
files: ['**/test/**/*.ts'],
rules: {
'no-console': 'warn',
'no-empty': 'off',
'@typescript-eslint/no-unsafe-function-type': 'warn',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/no-require-imports': 'off',
'@typescript-eslint/no-shadow': 'off',
'@typescript-eslint/no-floating-promises': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
},
},
// Examples: pure JS, no license header check (matches legacy ./examples/.eslintrc.js).
{
files: [
'examples/**/*.{js,mjs,cjs}',
'experimental/examples/**/*.{js,mjs,cjs}',
],
languageOptions: {
sourceType: 'commonjs',
globals: {
...globals.node,
...globals.mocha,
...globals.es2021,
},
parserOptions: {
ecmaVersion: 2021,
},
},
// The legacy `examples/.eslintrc.js` was a standalone config that didn't
// inherit the base, so prettier, quotes, and no-console were never
// enforced on example code. Preserve that behavior to keep this PR scoped
// to the ESLint 10 migration; tightening up examples is its own change.
rules: {
'yet-another-license-header/header': 'off',
'prettier/prettier': 'off',
'no-console': 'off',
'no-unused-vars': 'off',
quotes: 'off',
},
},
// e2e-tests use .mjs and may log freely.
{
files: ['e2e-tests/**/*.{js,mjs,cjs}'],
languageOptions: {
sourceType: 'module',
globals: { ...globals.node },
},
rules: {
'no-console': 'off',
},
},
// integration-tests use .js (CommonJS).
{
files: ['integration-tests/**/*.{js,cjs}'],
languageOptions: {
sourceType: 'commonjs',
globals: { ...globals.node, ...globals.mocha },
},
},
// Browser-only context-zone packages need the Zone global.
{
files: ['packages/opentelemetry-context-zone-peer-dep/**/*.ts'],
languageOptions: {
globals: { Zone: 'readonly' },
},
},
// shim-opencensus carries an upstream OpenCensus header for one file.
{
files: [
'experimental/packages/shim-opencensus/src/OpenCensusMetricProducer.ts',
],
rules: {
'yet-another-license-header/header': 'off',
},
}
);