forked from morganstanley/fdc3-web
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheslint.config.mjs
More file actions
144 lines (128 loc) · 6.08 KB
/
eslint.config.mjs
File metadata and controls
144 lines (128 loc) · 6.08 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
import 'eslint-plugin-prettier';
import { FlatCompat } from '@eslint/eslintrc';
import js from '@eslint/js';
import tsParser from '@typescript-eslint/parser';
import { defineConfig, globalIgnores } from 'eslint/config';
import licenseHeader from 'eslint-plugin-license-header';
import preferArrow from 'eslint-plugin-prefer-arrow';
import simpleImportSort from 'eslint-plugin-simple-import-sort';
import globals from 'globals';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import prettierConfig from './prettier.config.mjs';
import unusedImports from 'eslint-plugin-unused-imports';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all,
});
const additionalIgnorePatterns = process.env.additionalIgnorePatterns;
const overrideIgnorePatterns = process.env.overrideIgnorePatterns;
const optInRules = process.env.optInRules != null ? process.env.optInRules.split(',') : [];
const optInFunctionReturnType = 'explicit-function-return-type';
const ignores = globalIgnores(
overrideIgnorePatterns != null
? overrideIgnorePatterns.split(',')
: [
'**/dist/**/*',
'**/docs/**/*',
'**/node_modules/**/*',
...(additionalIgnorePatterns != null ? additionalIgnorePatterns.split(',') : []),
],
);
const apacheLicenseHeader = `/* Morgan Stanley makes this available to you under the Apache License,
* Version 2.0 (the "License"). You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership. Unless required by applicable law or agreed
* to in writing, software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions
* and limitations under the License. */`;
const rules = {
'lines-between-class-members': ['error', 'always', { exceptAfterSingleLine: true }],
'no-unused-vars': 'off', // typescript already warns about unused but allows some like _someVar
'@typescript-eslint/no-unused-vars': 'off', // typescript already warns about unused but allows some like _someVar
'@typescript-eslint/no-explicit-any': 'off', // 'spose... ¯\_(ツ)_/¯
'@typescript-eslint/explicit-module-boundary-types': 'off', // typescript already warns about unused but allows some like _someVar
'no-case-declarations': 'off', // prevents declaring variables within a case statement
'@typescript-eslint/no-inferrable-types': 'off', // forces removal of types for simple assignments like const myVar: string = "someString";
'@typescript-eslint/no-non-null-assertion': 'off', // allow bangs :'(
'@typescript-eslint/no-non-null-asserted-optional-chain': 'off', // allows bangs at the end of optional chaining :'(
'@typescript-eslint/explicit-member-accessibility': ['error', { overrides: { constructors: 'no-public' } }], // checks for public / private
'@typescript-eslint/explicit-function-return-type': ['warn', { allowExpressions: true }], // warn only about missing return types
'@typescript-eslint/prefer-as-const': 'off', // we don't really care if a const is marked as a const
'@typescript-eslint/no-empty-object-type': 'off', // we use empty interfaces as markers for functionality
'no-sequences': ['error', { allowInParentheses: false }], // prevents weird multiple expressions separated by comma
'sort-imports': 'off', // disabled default sorting as we have better option
'import/no-unresolved': 'off',
'simple-import-sort/imports': [
'error',
{
groups: [['^\\u0000', '^@?\\w', '^', '^\\.']], // disable blank lines between groups
},
], // alphabetically sorts imports
'import/no-duplicates': 'error', // removes duplicate imports
'prettier/prettier': ['error', prettierConfig], // runs prettier
'license-header/header': ['error', [apacheLicenseHeader]], // OSS license header
'unused-imports/no-unused-imports': 'error', // removes unused imports
};
if (typeof process.env.BUILD_TYPE === 'string' && process.env.BUILD_TYPE.toLowerCase() === 'release') {
rules['import/no-cycle'] = 'error';
}
if (optInRules.indexOf(optInFunctionReturnType) >= 0) {
rules['@typescript-eslint/explicit-function-return-type'] = ['error', { allowExpressions: true }];
}
export default defineConfig([
ignores,
{
extends: compat.extends(
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
'plugin:import/recommended',
'plugin:import/typescript',
),
plugins: {
'prefer-arrow': preferArrow,
'simple-import-sort': simpleImportSort,
'license-header': licenseHeader,
"unused-imports": unusedImports
},
languageOptions: {
globals: {
...globals.browser,
...globals.node,
},
parser: tsParser,
},
rules,
},
{
files: ['**/*.js'],
rules: {
'@typescript-eslint/no-require-imports': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
},
},
{
files: ['**/*.spec.ts'],
rules: {
'@typescript-eslint/no-require-imports': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/ban-types': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
},
},
{
files: ['**/*.config.js', '**/*.config.ts', '**/*.cjs', '**/*.mjs'],
rules: {
'license-header/header': 'off',
'@typescript-eslint/no-require-imports': 'off',
},
},
]);