• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import path from 'node:path';
17import { fileURLToPath } from 'node:url';
18import js from '@eslint/js';
19import { FlatCompat } from '@eslint/eslintrc';
20import eslint from '@eslint/js';
21import tseslint from 'typescript-eslint';
22
23const __filename = fileURLToPath(import.meta.url);
24const __dirname = path.dirname(__filename);
25const compat = new FlatCompat({
26  baseDirectory: __dirname,
27  recommendedConfig: js.configs.recommended,
28  allConfig: js.configs.all
29});
30
31export default tseslint.config(
32  {
33    ignores: [
34      'bin/**/*',
35      'build/**/*',
36      'bundle/**/*',
37      'dist/**/*',
38      'docs/**/*',
39      'node_modules/**/*',
40      'scripts/**/*',
41      'test/**/*',
42      '**/**.json',
43      '**/**.js'
44    ]
45  },
46  {
47    files: ['**/*.ts'],
48    extends: [eslint.configs.recommended, tseslint.configs.recommended],
49    plugins: {
50      '@typescript-eslint': tseslint.plugin
51    },
52
53    languageOptions: {
54      parser: tseslint.parser,
55      ecmaVersion: 'latest',
56      sourceType: 'module',
57      parserOptions: {
58        project: './tsconfig.json',
59        tsconfigRootDir: import.meta.dirname
60      }
61    },
62
63    rules: {
64      'arrow-body-style': ['error', 'always'],
65      camelcase: 'off',
66
67      'class-methods-use-this': [
68        'error',
69        {
70          exceptMethods: [],
71          enforceForClassFields: true
72        }
73      ],
74
75      complexity: [
76        'error',
77        {
78          max: 15
79        }
80      ],
81
82      'consistent-return': [
83        'error',
84        {
85          treatUndefinedAsUnspecified: false
86        }
87      ],
88
89      curly: ['error', 'all'],
90      'dot-notation': 'error',
91      eqeqeq: ['error', 'always'],
92
93      'max-depth': [
94        'error',
95        {
96          max: 4
97        }
98      ],
99
100      'multiline-comment-style': ['error', 'starred-block'],
101
102      'no-else-return': [
103        'error',
104        {
105          allowElseIf: true
106        }
107      ],
108
109      'no-extra-bind': 'error',
110      'no-lonely-if': 'error',
111      'no-unneeded-ternary': 'error',
112      'no-useless-return': 'error',
113      'no-var': 'error',
114      'prefer-const': 'error',
115      'spaced-comment': ['error', 'always'],
116      'one-var': ['error', 'never'],
117
118      'max-lines-per-function': [
119        'error',
120        {
121          max: 50
122        }
123      ],
124
125      '@typescript-eslint/explicit-function-return-type': 'error',
126      '@typescript-eslint/adjacent-overload-signatures': 'error',
127
128      '@typescript-eslint/explicit-member-accessibility': [
129        'error',
130        {
131          accessibility: 'no-public'
132        }
133      ],
134
135      '@typescript-eslint/method-signature-style': ['error', 'method'],
136      '@typescript-eslint/no-confusing-non-null-assertion': 'error',
137      '@typescript-eslint/no-confusing-void-expression': 'error',
138      '@typescript-eslint/no-explicit-any': 'warn',
139      '@typescript-eslint/no-extra-non-null-assertion': 'error',
140      '@typescript-eslint/no-meaningless-void-operator': 'error',
141      '@typescript-eslint/no-unnecessary-boolean-literal-compare': 'error',
142      '@typescript-eslint/no-unnecessary-condition': 'off',
143      '@typescript-eslint/no-unnecessary-type-assertion': 'error',
144      '@typescript-eslint/prefer-as-const': 'error',
145      '@typescript-eslint/prefer-optional-chain': 'error',
146      '@typescript-eslint/prefer-readonly': 'error',
147      '@typescript-eslint/consistent-type-imports': 'error',
148
149      '@typescript-eslint/naming-convention': [
150        'error',
151        {
152          selector: 'typeLike',
153          format: ['PascalCase']
154        }
155      ]
156    }
157  }
158);
159