@matrixai/lint 0.0.2-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 +201 -0
- package/README.md +172 -0
- package/dist/bin/lint.d.ts +3 -0
- package/dist/bin/lint.js +136 -0
- package/dist/bin/lint.js.map +1 -0
- package/dist/configs/js.d.ts +959 -0
- package/dist/configs/js.js +244 -0
- package/dist/configs/js.js.map +1 -0
- package/dist/plugins/eslint-plugin-matrixai.d.ts +18 -0
- package/dist/plugins/eslint-plugin-matrixai.js +13 -0
- package/dist/plugins/eslint-plugin-matrixai.js.map +1 -0
- package/dist/rules/no-aliased-imports.d.ts +12 -0
- package/dist/rules/no-aliased-imports.js +108 -0
- package/dist/rules/no-aliased-imports.js.map +1 -0
- package/dist/types.d.ts +9 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +65 -0
- package/dist/utils.js +187 -0
- package/dist/utils.js.map +1 -0
- package/flake.lock +78 -0
- package/jest.config.mjs +84 -0
- package/package.json +67 -0
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import globals from 'globals';
|
|
4
|
+
import _import from 'eslint-plugin-import';
|
|
5
|
+
import js from '@eslint/js';
|
|
6
|
+
import tsParser from '@typescript-eslint/parser';
|
|
7
|
+
import { FlatCompat } from '@eslint/eslintrc';
|
|
8
|
+
import { fixupPluginRules } from '@eslint/compat';
|
|
9
|
+
import matrixaiPlugin from '../plugins/eslint-plugin-matrixai.js';
|
|
10
|
+
import { resolveMatrixConfig } from '../utils.js';
|
|
11
|
+
const filename = fileURLToPath(import.meta.url);
|
|
12
|
+
const dirname = path.dirname(filename);
|
|
13
|
+
const compat = new FlatCompat({
|
|
14
|
+
baseDirectory: dirname,
|
|
15
|
+
recommendedConfig: js.configs.recommended,
|
|
16
|
+
allConfig: js.configs.all,
|
|
17
|
+
});
|
|
18
|
+
const config = [
|
|
19
|
+
...compat.extends('eslint:recommended', 'plugin:@typescript-eslint/recommended', 'plugin:prettier/recommended', 'plugin:react/recommended', 'plugin:react-hooks/recommended', 'plugin:tailwindcss/recommended', 'plugin:jsx-a11y/recommended'),
|
|
20
|
+
{
|
|
21
|
+
plugins: {
|
|
22
|
+
import: fixupPluginRules(_import),
|
|
23
|
+
'@matrixai': matrixaiPlugin,
|
|
24
|
+
},
|
|
25
|
+
settings: {
|
|
26
|
+
react: {
|
|
27
|
+
version: 'detect',
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
languageOptions: {
|
|
31
|
+
globals: {
|
|
32
|
+
...globals.browser,
|
|
33
|
+
...globals.commonjs,
|
|
34
|
+
...globals.node,
|
|
35
|
+
...globals.jest,
|
|
36
|
+
},
|
|
37
|
+
parser: tsParser,
|
|
38
|
+
ecmaVersion: 5,
|
|
39
|
+
sourceType: 'module',
|
|
40
|
+
parserOptions: {
|
|
41
|
+
project: resolveMatrixConfig().tsconfigPaths,
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
rules: {
|
|
45
|
+
// MatrixAI rules
|
|
46
|
+
'@matrixai/no-aliased-imports': [
|
|
47
|
+
'error',
|
|
48
|
+
{
|
|
49
|
+
aliases: [{ prefix: '#', target: 'src' }],
|
|
50
|
+
includeFolders: ['src'],
|
|
51
|
+
autoFix: true,
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
// React rules
|
|
55
|
+
'react/react-in-jsx-scope': 0,
|
|
56
|
+
'react/no-unknown-property': 'off',
|
|
57
|
+
'react/button-has-type': 'error',
|
|
58
|
+
'react/no-unused-prop-types': 'error',
|
|
59
|
+
'react/jsx-pascal-case': 'error',
|
|
60
|
+
'react/jsx-no-script-url': 'error',
|
|
61
|
+
'react/no-children-prop': 'error',
|
|
62
|
+
'react/no-danger': 'error',
|
|
63
|
+
'react/no-danger-with-children': 'error',
|
|
64
|
+
'react/no-unstable-nested-components': ['error', { allowAsProps: true }],
|
|
65
|
+
'react/jsx-fragments': 'error',
|
|
66
|
+
'react/destructuring-assignment': [
|
|
67
|
+
'error',
|
|
68
|
+
'always',
|
|
69
|
+
{ destructureInSignature: 'always' },
|
|
70
|
+
],
|
|
71
|
+
'react/jsx-no-leaked-render': ['error', { validStrategies: ['ternary'] }],
|
|
72
|
+
'react/function-component-definition': [
|
|
73
|
+
'warn',
|
|
74
|
+
{ namedComponents: 'arrow-function' },
|
|
75
|
+
],
|
|
76
|
+
'react/jsx-key': [
|
|
77
|
+
'error',
|
|
78
|
+
{
|
|
79
|
+
checkFragmentShorthand: true,
|
|
80
|
+
checkKeyMustBeforeSpread: true,
|
|
81
|
+
warnOnDuplicates: true,
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
'react/jsx-no-useless-fragment': 'warn',
|
|
85
|
+
'react/jsx-curly-brace-presence': 'warn',
|
|
86
|
+
'react/no-typos': 'warn',
|
|
87
|
+
'react/display-name': 'warn',
|
|
88
|
+
'react/jsx-sort-props': 'warn',
|
|
89
|
+
'react/jsx-one-expression-per-line': 'off',
|
|
90
|
+
'react/prop-types': 'off',
|
|
91
|
+
'@typescript-eslint/no-floating-promises': [
|
|
92
|
+
'error',
|
|
93
|
+
{
|
|
94
|
+
ignoreVoid: true,
|
|
95
|
+
ignoreIIFE: true,
|
|
96
|
+
},
|
|
97
|
+
],
|
|
98
|
+
'@typescript-eslint/no-misused-promises': [
|
|
99
|
+
'error',
|
|
100
|
+
{
|
|
101
|
+
checksVoidReturn: false,
|
|
102
|
+
},
|
|
103
|
+
],
|
|
104
|
+
'@typescript-eslint/await-thenable': ['error'],
|
|
105
|
+
'linebreak-style': ['error', 'unix'],
|
|
106
|
+
'no-empty': 1,
|
|
107
|
+
'no-useless-catch': 1,
|
|
108
|
+
'no-prototype-builtins': 1,
|
|
109
|
+
'no-constant-condition': 0,
|
|
110
|
+
'no-useless-escape': 0,
|
|
111
|
+
'no-console': 'error',
|
|
112
|
+
'no-restricted-globals': [
|
|
113
|
+
'error',
|
|
114
|
+
{
|
|
115
|
+
name: 'global',
|
|
116
|
+
message: 'Use `globalThis` instead',
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
name: 'window',
|
|
120
|
+
message: 'Use `globalThis` instead',
|
|
121
|
+
},
|
|
122
|
+
],
|
|
123
|
+
'prefer-rest-params': 0,
|
|
124
|
+
'require-yield': 0,
|
|
125
|
+
eqeqeq: ['error', 'smart'],
|
|
126
|
+
'spaced-comment': [
|
|
127
|
+
'warn',
|
|
128
|
+
'always',
|
|
129
|
+
{
|
|
130
|
+
line: {
|
|
131
|
+
exceptions: ['-'],
|
|
132
|
+
},
|
|
133
|
+
block: {
|
|
134
|
+
exceptions: ['*'],
|
|
135
|
+
},
|
|
136
|
+
markers: ['/'],
|
|
137
|
+
},
|
|
138
|
+
],
|
|
139
|
+
'capitalized-comments': [
|
|
140
|
+
'warn',
|
|
141
|
+
'always',
|
|
142
|
+
{
|
|
143
|
+
ignoreInlineComments: true,
|
|
144
|
+
ignoreConsecutiveComments: true,
|
|
145
|
+
},
|
|
146
|
+
],
|
|
147
|
+
curly: ['error', 'multi-line', 'consistent'],
|
|
148
|
+
'import/order': [
|
|
149
|
+
'error',
|
|
150
|
+
{
|
|
151
|
+
groups: [
|
|
152
|
+
'type',
|
|
153
|
+
'builtin',
|
|
154
|
+
'external',
|
|
155
|
+
'internal',
|
|
156
|
+
'index',
|
|
157
|
+
'sibling',
|
|
158
|
+
'parent',
|
|
159
|
+
'object',
|
|
160
|
+
],
|
|
161
|
+
pathGroups: [
|
|
162
|
+
{
|
|
163
|
+
pattern: '@',
|
|
164
|
+
group: 'internal',
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
pattern: '@/**',
|
|
168
|
+
group: 'internal',
|
|
169
|
+
},
|
|
170
|
+
],
|
|
171
|
+
pathGroupsExcludedImportTypes: ['type'],
|
|
172
|
+
'newlines-between': 'never',
|
|
173
|
+
},
|
|
174
|
+
],
|
|
175
|
+
'@typescript-eslint/no-require-imports': 0,
|
|
176
|
+
'@typescript-eslint/no-namespace': 0,
|
|
177
|
+
'@typescript-eslint/no-explicit-any': 0,
|
|
178
|
+
'@typescript-eslint/explicit-module-boundary-types': 0,
|
|
179
|
+
'@typescript-eslint/no-unused-vars': [
|
|
180
|
+
'warn',
|
|
181
|
+
{
|
|
182
|
+
varsIgnorePattern: '^_',
|
|
183
|
+
argsIgnorePattern: '^_',
|
|
184
|
+
},
|
|
185
|
+
],
|
|
186
|
+
'@typescript-eslint/no-inferrable-types': 0,
|
|
187
|
+
'@typescript-eslint/no-non-null-assertion': 0,
|
|
188
|
+
'@typescript-eslint/no-this-alias': 0,
|
|
189
|
+
'@typescript-eslint/no-var-requires': 0,
|
|
190
|
+
'@typescript-eslint/no-empty-function': 0,
|
|
191
|
+
'@typescript-eslint/no-empty-interface': 0,
|
|
192
|
+
'@typescript-eslint/consistent-type-imports': ['error'],
|
|
193
|
+
'@typescript-eslint/consistent-type-exports': ['error'],
|
|
194
|
+
'no-throw-literal': 'off',
|
|
195
|
+
'@typescript-eslint/no-throw-literal': 'off',
|
|
196
|
+
'@typescript-eslint/naming-convention': [
|
|
197
|
+
'error',
|
|
198
|
+
{
|
|
199
|
+
selector: 'function',
|
|
200
|
+
format: ['camelCase', 'PascalCase'],
|
|
201
|
+
leadingUnderscore: 'allow',
|
|
202
|
+
trailingUnderscore: 'allowSingleOrDouble',
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
selector: 'variable',
|
|
206
|
+
format: ['camelCase', 'UPPER_CASE', 'PascalCase'],
|
|
207
|
+
leadingUnderscore: 'allow',
|
|
208
|
+
trailingUnderscore: 'allowSingleOrDouble',
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
selector: 'parameter',
|
|
212
|
+
format: ['camelCase'],
|
|
213
|
+
leadingUnderscore: 'allow',
|
|
214
|
+
trailingUnderscore: 'allowSingleOrDouble',
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
selector: 'typeLike',
|
|
218
|
+
format: ['PascalCase'],
|
|
219
|
+
trailingUnderscore: 'allowSingleOrDouble',
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
selector: 'enumMember',
|
|
223
|
+
format: ['PascalCase', 'UPPER_CASE'],
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
selector: 'objectLiteralProperty',
|
|
227
|
+
format: null,
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
selector: 'typeProperty',
|
|
231
|
+
format: null,
|
|
232
|
+
},
|
|
233
|
+
],
|
|
234
|
+
'@typescript-eslint/ban-ts-comment': [
|
|
235
|
+
'error',
|
|
236
|
+
{
|
|
237
|
+
'ts-ignore': 'allow-with-description',
|
|
238
|
+
},
|
|
239
|
+
],
|
|
240
|
+
},
|
|
241
|
+
},
|
|
242
|
+
];
|
|
243
|
+
export default config;
|
|
244
|
+
//# sourceMappingURL=js.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"js.js","sourceRoot":"","sources":["../../src/configs/js.ts"],"names":[],"mappings":"AACA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,OAAO,MAAM,sBAAsB,CAAC;AAC3C,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,QAAQ,MAAM,2BAA2B,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,cAAc,MAAM,sCAAsC,CAAC;AAClE,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAElD,MAAM,QAAQ,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAChD,MAAM,OAAO,GAAG,IAAI,CAA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C"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
declare const matrixaiPlugin: {
|
|
2
|
+
meta: {
|
|
3
|
+
name: string;
|
|
4
|
+
version: string;
|
|
5
|
+
};
|
|
6
|
+
rules: {
|
|
7
|
+
'no-aliased-imports': import("@typescript-eslint/utils/ts-eslint").RuleModule<"noAlias" | "noAliasNoAutofix", [{
|
|
8
|
+
aliases: {
|
|
9
|
+
prefix: string;
|
|
10
|
+
target: string;
|
|
11
|
+
}[];
|
|
12
|
+
includeFolders: string[];
|
|
13
|
+
autoFix: boolean;
|
|
14
|
+
}], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
15
|
+
};
|
|
16
|
+
configs: {};
|
|
17
|
+
};
|
|
18
|
+
export default matrixaiPlugin;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import noAliasedImportsRule from '../rules/no-aliased-imports.js';
|
|
2
|
+
const matrixaiPlugin = {
|
|
3
|
+
meta: {
|
|
4
|
+
name: 'eslint-plugin-matrixai',
|
|
5
|
+
version: '0.0.1',
|
|
6
|
+
},
|
|
7
|
+
rules: {
|
|
8
|
+
'no-aliased-imports': noAliasedImportsRule,
|
|
9
|
+
},
|
|
10
|
+
configs: {},
|
|
11
|
+
};
|
|
12
|
+
export default matrixaiPlugin;
|
|
13
|
+
//# sourceMappingURL=eslint-plugin-matrixai.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eslint-plugin-matrixai.js","sourceRoot":"","sources":["../../src/plugins/eslint-plugin-matrixai.ts"],"names":[],"mappings":"AAAA,OAAO,oBAAoB,MAAM,gCAAgC,CAAC;AAElE,MAAM,cAAc,GAAG;IACrB,IAAI,EAAE;QACJ,IAAI,EAAE,wBAAwB;QAC9B,OAAO,EAAE,OAAO;KACjB;IACD,KAAK,EAAE;QACL,oBAAoB,EAAE,oBAAoB;KAC3C;IACD,OAAO,EAAE,EAAE;CACZ,CAAC;AAEF,eAAe,cAAc,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { RuleModule } from '@typescript-eslint/utils/ts-eslint';
|
|
2
|
+
export declare const noAliasedImportsRule: RuleModule<'noAlias' | 'noAliasNoAutofix', [
|
|
3
|
+
{
|
|
4
|
+
aliases: {
|
|
5
|
+
prefix: string;
|
|
6
|
+
target: string;
|
|
7
|
+
}[];
|
|
8
|
+
includeFolders: string[];
|
|
9
|
+
autoFix: boolean;
|
|
10
|
+
}
|
|
11
|
+
]>;
|
|
12
|
+
export default noAliasedImportsRule;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
export const noAliasedImportsRule = {
|
|
3
|
+
meta: {
|
|
4
|
+
type: 'suggestion',
|
|
5
|
+
fixable: 'code',
|
|
6
|
+
hasSuggestions: true,
|
|
7
|
+
schema: [
|
|
8
|
+
{
|
|
9
|
+
type: 'object',
|
|
10
|
+
properties: {
|
|
11
|
+
// We'll allow multiple alias mappings
|
|
12
|
+
aliases: {
|
|
13
|
+
type: 'array',
|
|
14
|
+
items: {
|
|
15
|
+
type: 'object',
|
|
16
|
+
properties: {
|
|
17
|
+
prefix: { type: 'string' },
|
|
18
|
+
target: { type: 'string' },
|
|
19
|
+
},
|
|
20
|
+
required: ['prefix', 'target'],
|
|
21
|
+
},
|
|
22
|
+
default: [{ prefix: '#', target: 'src' }],
|
|
23
|
+
},
|
|
24
|
+
// Folders or partial strings that the filename must include
|
|
25
|
+
// in order for us to apply the rule
|
|
26
|
+
includeFolders: {
|
|
27
|
+
type: 'array',
|
|
28
|
+
items: { type: 'string' },
|
|
29
|
+
default: ['src'],
|
|
30
|
+
},
|
|
31
|
+
autoFix: {
|
|
32
|
+
type: 'boolean',
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
additionalProperties: false,
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
messages: {
|
|
39
|
+
noAlias: 'Use relative import instead of alias import in src files "{{ aliasImport }}".',
|
|
40
|
+
noAliasNoAutofix: 'Use relative import instead of alias import in src files "{{ aliasImport }}" (auto-fix is disabled)',
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
// Provide defaults if none are given
|
|
44
|
+
defaultOptions: [
|
|
45
|
+
{
|
|
46
|
+
aliases: [{ prefix: '#', target: 'src' }],
|
|
47
|
+
includeFolders: ['src'],
|
|
48
|
+
autoFix: false,
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
create(context) {
|
|
52
|
+
const options = context.options[0] || {};
|
|
53
|
+
const { aliases = [{ prefix: '#', target: 'src' }], includeFolders = ['src'], autoFix = false, } = options;
|
|
54
|
+
return {
|
|
55
|
+
ImportDeclaration(node) {
|
|
56
|
+
const importPath = node.source.value;
|
|
57
|
+
// The absolute path of the current file being linted
|
|
58
|
+
const filename = context.filename;
|
|
59
|
+
// 1) Check if the file is in one of the "includeFolders"
|
|
60
|
+
const isInIncludedFolder = includeFolders.some((folder) => {
|
|
61
|
+
return (filename.includes(`${path.sep}${folder}${path.sep}`) ||
|
|
62
|
+
filename.endsWith(`${path.sep}${folder}`));
|
|
63
|
+
// ^ endsWith check so that if 'src' is the last part of the path, it still matches
|
|
64
|
+
});
|
|
65
|
+
// File is not in any of the included folders, so skip
|
|
66
|
+
if (!isInIncludedFolder) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
// 2) Check if the import path starts with any of the alias prefixes
|
|
70
|
+
const matchedAlias = aliases.find((aliasObj) => importPath.startsWith(aliasObj.prefix));
|
|
71
|
+
// Doesn't match any alias prefix, so skip
|
|
72
|
+
if (matchedAlias == null) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
// For example: prefix = '#' => target = 'src'
|
|
76
|
+
const { prefix, target } = matchedAlias;
|
|
77
|
+
// LocalPart is the substring after the alias prefix
|
|
78
|
+
// e.g. `#db/utils.js` => `db/utils.js`
|
|
79
|
+
const localPart = importPath.slice(prefix.length);
|
|
80
|
+
// 3) Build the absolute path to the *real* file
|
|
81
|
+
// e.g. => <PROJECT_ROOT>/src/db/utils.js
|
|
82
|
+
// or if alias is { prefix: '@', target: 'lib' } => <PROJECT_ROOT>/lib/db/utils.js
|
|
83
|
+
const projectRoot = context.cwd;
|
|
84
|
+
const absoluteImportPath = path.join(projectRoot, target, localPart);
|
|
85
|
+
// 4) Compute the relative path from the current file
|
|
86
|
+
const currentFileDir = path.dirname(filename);
|
|
87
|
+
let relativePath = path.relative(currentFileDir, absoluteImportPath);
|
|
88
|
+
if (!relativePath.startsWith('.')) {
|
|
89
|
+
relativePath = `.${path.sep}${relativePath}`;
|
|
90
|
+
}
|
|
91
|
+
// If autoFix is false, don't give a fix - forces manual fix.
|
|
92
|
+
const fix = autoFix
|
|
93
|
+
? (fixer) => {
|
|
94
|
+
return fixer.replaceTextRange([node.source.range[0], node.source.range[1]], `'${relativePath}'`);
|
|
95
|
+
}
|
|
96
|
+
: null;
|
|
97
|
+
context.report({
|
|
98
|
+
node: node.source,
|
|
99
|
+
messageId: autoFix ? 'noAlias' : 'noAliasNoAutofix',
|
|
100
|
+
data: { aliasImport: importPath },
|
|
101
|
+
fix,
|
|
102
|
+
});
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
export default noAliasedImportsRule;
|
|
108
|
+
//# sourceMappingURL=no-aliased-imports.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-aliased-imports.js","sourceRoot":"","sources":["../../src/rules/no-aliased-imports.ts"],"names":[],"mappings":"AACA,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,MAAM,CAAC,MAAM,oBAAoB,GAS7B;IACF,IAAI,EAAE;QACJ,IAAI,EAAE,YAAY;QAClB,OAAO,EAAE,MAAM;QACf,cAAc,EAAE,IAAI;QACpB,MAAM,EAAE;YACN;gBACE,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE;oBACV,sCAAsC;oBACtC,OAAO,EAAE;wBACP,I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QAAQ,CAAC,cAAc,EAAE,kBAAkB,CAAC,CAAC;gBACrE,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;oBACjC,YAAY,GAAG,IAAI,IAAI,CAAC,GAAG,GAAG,YAAY,EAAE,CAAC;iBAC9C;gBACD,6DAA6D;gBAC7D,MAAM,GAAG,GAAG,OAAO;oBACjB,CAAC,CAAC,CAAC,KAAK,EAAE,EAAE;wBACR,OAAO,KAAK,CAAC,gBAAgB,CAC3B,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAC5C,IAAI,YAAY,GAAG,CACpB,CAAC;oBACJ,CAAC;oBACH,CAAC,CAAC,IAAI,CAAC;gBAET,OAAO,CAAC,MAAM,CAAC;oBACb,IAAI,EAAE,IAAI,CAAC,MAAM;oBACjB,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,kBAAkB;oBACnD,IAAI,EAAE,EAAE,WAAW,EAAE,UAAU,EAAE;oBACjC,GAAG;iBACJ,CAAC,CAAC;YACL,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC;AAEF,eAAe,oBAAoB,CAAC"}
|
package/dist/types.d.ts
ADDED
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { MatrixAILintCfg } from './types.js';
|
|
2
|
+
declare function runESLint({ fix, configPath, }: {
|
|
3
|
+
fix: boolean;
|
|
4
|
+
configPath?: string;
|
|
5
|
+
}): Promise<void>;
|
|
6
|
+
/**
|
|
7
|
+
* Find the user's ESLint config file in the current working directory.
|
|
8
|
+
* It looks for the following files:
|
|
9
|
+
* - eslint.config.js
|
|
10
|
+
* - eslint.config.mjs
|
|
11
|
+
* - eslint.config.cjs
|
|
12
|
+
* - eslint.config.ts
|
|
13
|
+
*
|
|
14
|
+
* @param repoRoot The root directory of the repository (default: process.cwd())
|
|
15
|
+
* @returns The path to the ESLint config file, or null if not found.
|
|
16
|
+
*/
|
|
17
|
+
declare function findUserESLintConfig(repoRoot?: string): string | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Collect all Markdown files in a directory and its subdirectories.
|
|
20
|
+
*
|
|
21
|
+
* @param dir The directory to search in.
|
|
22
|
+
* @returns An array of paths to Markdown files.
|
|
23
|
+
*/
|
|
24
|
+
declare function collectMarkdown(dir: string): string[];
|
|
25
|
+
/**
|
|
26
|
+
* Check if a command exists in the system PATH.
|
|
27
|
+
*
|
|
28
|
+
* @param cmd The command to check.
|
|
29
|
+
* @returns True if the command exists, false otherwise.
|
|
30
|
+
*/
|
|
31
|
+
declare function commandExists(cmd: string): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Loads and sanitises MatrixAI‑linter config for a repo.
|
|
34
|
+
*
|
|
35
|
+
* - Reads `matrixai-lint-config.json` in `repoRoot` (if present).
|
|
36
|
+
* - Throws if the JSON is invalid.
|
|
37
|
+
* - Extracts `tsconfigPaths` & `forceInclude`, coercing each to `string[]`.
|
|
38
|
+
* - Resolves `tsconfigPaths` to absolute paths and keeps only files that exist.
|
|
39
|
+
* - If none remain, falls back to `repoRoot/tsconfig.json` when available.
|
|
40
|
+
* - Strips leading “./” from every `forceInclude` glob.
|
|
41
|
+
*
|
|
42
|
+
* Returns a normalised `{ tsconfigPaths, forceInclude }`.
|
|
43
|
+
*/
|
|
44
|
+
declare function resolveMatrixConfig(repoRoot?: string): MatrixAILintCfg;
|
|
45
|
+
/**
|
|
46
|
+
* Builds file and ignore patterns based on a given TypeScript configuration file path,
|
|
47
|
+
* with optional forced inclusion of specific paths.
|
|
48
|
+
*
|
|
49
|
+
* @param tsconfigPath - The path to the TypeScript configuration file (tsconfig.json).
|
|
50
|
+
* @param forceInclude - An optional array of paths or patterns to forcefully include,
|
|
51
|
+
* even if they overlap with excluded patterns.
|
|
52
|
+
* @returns An object containing:
|
|
53
|
+
* - `files`: An array of glob patterns for files to include.
|
|
54
|
+
* - `ignore`: An array of glob patterns for files or directories to ignore.
|
|
55
|
+
*
|
|
56
|
+
* The function reads the `include` and `exclude` properties from the TypeScript
|
|
57
|
+
* configuration file, processes them into glob patterns, and applies overrides
|
|
58
|
+
* based on the `forceInclude` parameter. If no `exclude` patterns are specified,
|
|
59
|
+
* default ignore patterns for common directories like `node_modules` are added.
|
|
60
|
+
*/
|
|
61
|
+
declare function buildPatterns(tsconfigPath: string, forceInclude?: string[]): {
|
|
62
|
+
files: string[];
|
|
63
|
+
ignore: string[];
|
|
64
|
+
};
|
|
65
|
+
export { runESLint, findUserESLintConfig, collectMarkdown, commandExists, resolveMatrixConfig, buildPatterns, };
|