@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
package/dist/utils.js
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import process from 'node:process';
|
|
3
|
+
import childProcess from 'node:child_process';
|
|
4
|
+
import fs from 'node:fs';
|
|
5
|
+
import url from 'node:url';
|
|
6
|
+
import ts from 'typescript';
|
|
7
|
+
import { ESLint } from 'eslint';
|
|
8
|
+
/* eslint-disable no-console */
|
|
9
|
+
async function runESLint({ fix, configPath, }) {
|
|
10
|
+
const dirname = path.dirname(url.fileURLToPath(import.meta.url));
|
|
11
|
+
const defaultConfigPath = path.resolve(dirname, './configs/js.js');
|
|
12
|
+
const matrixaiLintConfig = resolveMatrixConfig();
|
|
13
|
+
const forceInclude = matrixaiLintConfig.forceInclude;
|
|
14
|
+
const tsconfigPaths = matrixaiLintConfig.tsconfigPaths;
|
|
15
|
+
if (tsconfigPaths.length === 0) {
|
|
16
|
+
console.error('[matrixai-lint] ⚠ No tsconfig.json files found.');
|
|
17
|
+
}
|
|
18
|
+
console.log(`Found ${tsconfigPaths.length} tsconfig.json files:`);
|
|
19
|
+
tsconfigPaths.forEach((tsconfigPath) => console.log(' ' + tsconfigPath));
|
|
20
|
+
const { files: lintFiles, ignore } = buildPatterns(tsconfigPaths[0], forceInclude);
|
|
21
|
+
console.log('Linting files:');
|
|
22
|
+
lintFiles.forEach((file) => console.log(' ' + file));
|
|
23
|
+
const eslint = new ESLint({
|
|
24
|
+
overrideConfigFile: configPath || defaultConfigPath,
|
|
25
|
+
fix,
|
|
26
|
+
errorOnUnmatchedPattern: false,
|
|
27
|
+
warnIgnored: false,
|
|
28
|
+
ignorePatterns: ignore,
|
|
29
|
+
});
|
|
30
|
+
const results = await eslint.lintFiles(lintFiles);
|
|
31
|
+
if (fix) {
|
|
32
|
+
await ESLint.outputFixes(results);
|
|
33
|
+
}
|
|
34
|
+
const formatter = await eslint.loadFormatter('stylish');
|
|
35
|
+
const resultText = formatter.format(results);
|
|
36
|
+
console.log(resultText);
|
|
37
|
+
/* eslint-enable no-console */
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Find the user's ESLint config file in the current working directory.
|
|
41
|
+
* It looks for the following files:
|
|
42
|
+
* - eslint.config.js
|
|
43
|
+
* - eslint.config.mjs
|
|
44
|
+
* - eslint.config.cjs
|
|
45
|
+
* - eslint.config.ts
|
|
46
|
+
*
|
|
47
|
+
* @param repoRoot The root directory of the repository (default: process.cwd())
|
|
48
|
+
* @returns The path to the ESLint config file, or null if not found.
|
|
49
|
+
*/
|
|
50
|
+
function findUserESLintConfig(repoRoot = process.cwd()) {
|
|
51
|
+
const candidates = [
|
|
52
|
+
'eslint.config.js',
|
|
53
|
+
'eslint.config.mjs',
|
|
54
|
+
'eslint.config.cjs',
|
|
55
|
+
'eslint.config.ts',
|
|
56
|
+
];
|
|
57
|
+
for (const file of candidates) {
|
|
58
|
+
const abs = path.join(repoRoot, file);
|
|
59
|
+
if (fs.existsSync(abs))
|
|
60
|
+
return abs;
|
|
61
|
+
}
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Collect all Markdown files in a directory and its subdirectories.
|
|
66
|
+
*
|
|
67
|
+
* @param dir The directory to search in.
|
|
68
|
+
* @returns An array of paths to Markdown files.
|
|
69
|
+
*/
|
|
70
|
+
function collectMarkdown(dir) {
|
|
71
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true, recursive: true });
|
|
72
|
+
return entries
|
|
73
|
+
.filter((e) => e.isFile() && /\.(md|mdx)$/i.test(e.name))
|
|
74
|
+
.map((e) => path.join(dir, e.name));
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Check if a command exists in the system PATH.
|
|
78
|
+
*
|
|
79
|
+
* @param cmd The command to check.
|
|
80
|
+
* @returns True if the command exists, false otherwise.
|
|
81
|
+
*/
|
|
82
|
+
function commandExists(cmd) {
|
|
83
|
+
const whichCmd = process.platform === 'win32' ? 'where' : 'which';
|
|
84
|
+
const result = childProcess.spawnSync(whichCmd, [cmd], { stdio: 'ignore' });
|
|
85
|
+
return result.status === 0;
|
|
86
|
+
}
|
|
87
|
+
// Checks if the value is an object and not null
|
|
88
|
+
// and then casts it to RawMatrixCfg. If the value is not an object or is null,
|
|
89
|
+
// it returns undefined.
|
|
90
|
+
function asRawMatrixCfg(v) {
|
|
91
|
+
return typeof v === 'object' && v !== null ? v : undefined;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Loads and sanitises MatrixAI‑linter config for a repo.
|
|
95
|
+
*
|
|
96
|
+
* - Reads `matrixai-lint-config.json` in `repoRoot` (if present).
|
|
97
|
+
* - Throws if the JSON is invalid.
|
|
98
|
+
* - Extracts `tsconfigPaths` & `forceInclude`, coercing each to `string[]`.
|
|
99
|
+
* - Resolves `tsconfigPaths` to absolute paths and keeps only files that exist.
|
|
100
|
+
* - If none remain, falls back to `repoRoot/tsconfig.json` when available.
|
|
101
|
+
* - Strips leading “./” from every `forceInclude` glob.
|
|
102
|
+
*
|
|
103
|
+
* Returns a normalised `{ tsconfigPaths, forceInclude }`.
|
|
104
|
+
*/
|
|
105
|
+
function resolveMatrixConfig(repoRoot = process.cwd()) {
|
|
106
|
+
const cfgPath = path.join(repoRoot, 'matrixai-lint-config.json');
|
|
107
|
+
let rawCfg = {};
|
|
108
|
+
if (fs.existsSync(cfgPath)) {
|
|
109
|
+
try {
|
|
110
|
+
const text = fs.readFileSync(cfgPath, 'utf8').trim();
|
|
111
|
+
rawCfg = text.length > 0 ? JSON.parse(text) : {};
|
|
112
|
+
}
|
|
113
|
+
catch (e) {
|
|
114
|
+
throw new Error(`[matrixai-lint] ✖ matrixai-lint-config.json has been provided but it is not valid JSON.\n ${e}`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
const cfg = asRawMatrixCfg(rawCfg);
|
|
118
|
+
const tsconfigPaths = toStringArray(cfg?.tsconfigPaths ?? [])
|
|
119
|
+
.map((p) => path.resolve(repoRoot, p))
|
|
120
|
+
.filter((p) => {
|
|
121
|
+
if (fs.existsSync(p))
|
|
122
|
+
return true;
|
|
123
|
+
return false;
|
|
124
|
+
});
|
|
125
|
+
const forceInclude = toStringArray(cfg?.forceInclude ?? []).map((g) => g.replace(/^\.\//, ''));
|
|
126
|
+
// Fallback to root tsconfig if no tsconfigPaths are provided
|
|
127
|
+
// and the root tsconfig exists
|
|
128
|
+
if (tsconfigPaths.length === 0) {
|
|
129
|
+
const rootTs = path.join(repoRoot, 'tsconfig.json');
|
|
130
|
+
if (fs.existsSync(rootTs))
|
|
131
|
+
tsconfigPaths.push(rootTs);
|
|
132
|
+
}
|
|
133
|
+
return { tsconfigPaths, forceInclude };
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Converts a value into an array of strings.
|
|
137
|
+
*
|
|
138
|
+
* - If the value is a string, it returns an array containing that string.
|
|
139
|
+
* - If the value is an array, it filters the array to include only strings.
|
|
140
|
+
* - For any other type, it returns an empty array.
|
|
141
|
+
*
|
|
142
|
+
* @param value The value to convert.
|
|
143
|
+
* @returns An array of strings.
|
|
144
|
+
*/
|
|
145
|
+
function toStringArray(value) {
|
|
146
|
+
if (typeof value === 'string') {
|
|
147
|
+
return [value];
|
|
148
|
+
}
|
|
149
|
+
if (Array.isArray(value)) {
|
|
150
|
+
return value.filter((item) => typeof item === 'string');
|
|
151
|
+
}
|
|
152
|
+
return [];
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Builds file and ignore patterns based on a given TypeScript configuration file path,
|
|
156
|
+
* with optional forced inclusion of specific paths.
|
|
157
|
+
*
|
|
158
|
+
* @param tsconfigPath - The path to the TypeScript configuration file (tsconfig.json).
|
|
159
|
+
* @param forceInclude - An optional array of paths or patterns to forcefully include,
|
|
160
|
+
* even if they overlap with excluded patterns.
|
|
161
|
+
* @returns An object containing:
|
|
162
|
+
* - `files`: An array of glob patterns for files to include.
|
|
163
|
+
* - `ignore`: An array of glob patterns for files or directories to ignore.
|
|
164
|
+
*
|
|
165
|
+
* The function reads the `include` and `exclude` properties from the TypeScript
|
|
166
|
+
* configuration file, processes them into glob patterns, and applies overrides
|
|
167
|
+
* based on the `forceInclude` parameter. If no `exclude` patterns are specified,
|
|
168
|
+
* default ignore patterns for common directories like `node_modules` are added.
|
|
169
|
+
*/
|
|
170
|
+
function buildPatterns(tsconfigPath, forceInclude = []) {
|
|
171
|
+
const { config } = ts.readConfigFile(tsconfigPath, ts.sys.readFile);
|
|
172
|
+
const strip = (p) => p.replace(/^\.\//, '');
|
|
173
|
+
const include = (config.include ?? []).map(strip);
|
|
174
|
+
const exclude = (config.exclude ?? []).map(strip);
|
|
175
|
+
// ForceInclude overrides exclude
|
|
176
|
+
const ignore = exclude.filter((ex) => !forceInclude.some((fi) => fi.startsWith(ex) || ex.startsWith(fi)));
|
|
177
|
+
const files = [
|
|
178
|
+
...include.map((g) => `${g}.{js,mjs,ts,mts,jsx,tsx,json}`),
|
|
179
|
+
...forceInclude.map((g) => `${g}.{js,mjs,ts,mts,jsx,tsx,json}`),
|
|
180
|
+
];
|
|
181
|
+
if (exclude.length <= 0) {
|
|
182
|
+
ignore.push('node_modules/**', 'bower_components/**', 'jspm_packages/**');
|
|
183
|
+
}
|
|
184
|
+
return { files, ignore };
|
|
185
|
+
}
|
|
186
|
+
export { runESLint, findUserESLintConfig, collectMarkdown, commandExists, resolveMatrixConfig, buildPatterns, };
|
|
187
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,YAAY,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,GAAG,MAAM,UAAU,CAAC;AAC3B,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,+BAA+B;AAC/B,KAAK,UAAU,SAAS,CAAC,EACvB,GAAG,EACH,UAAU,GAIX;IACC,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IACjE,MAAM,iBAAiB,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAC;IAEnE,MAAM,kBAAkB,GAAG,mBAAmB,EAAE,CAAC;IACjD,MAAM,YAAY,GAAG,kBAAkB,CAAC,YAAY,CAAC;IACrD,MAAM,aAAa,GAAG,kBAAkB,CAAC,aAAa,CAAC;IAEvD,IAAI,aAAa,CAAC,MAAM,KAAK,CAAC,EAAE;QAC9B,OAAO,CAAC,KAAK,CAAC,mDAAmD,CAAC,CAAC;KACpE;IAED,O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,EAAE,CAAC,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAC3E,CAAC;IAEF,MAAM,KAAK,GAAG;QACZ,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,+BAA+B,CAAC;QAC1D,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,+BAA+B,CAAC;KAChE,CAAC;IAEF,IAAI,OAAO,CAAC,MAAM,IAAI,CAAC,EAAE;QACvB,MAAM,CAAC,IAAI,CAAC,iBAAiB,EAAE,qBAAqB,EAAE,kBAAkB,CAAC,CAAC;KAC3E;IAED,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;AAC3B,CAAC;AAED,OAAO,EACL,SAAS,EACT,oBAAoB,EACpB,eAAe,EACf,aAAa,EACb,mBAAmB,EACnB,aAAa,GACd,CAAC"}
|
package/flake.lock
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
{
|
|
2
|
+
"nodes": {
|
|
3
|
+
"flake-utils": {
|
|
4
|
+
"inputs": {
|
|
5
|
+
"systems": "systems"
|
|
6
|
+
},
|
|
7
|
+
"locked": {
|
|
8
|
+
"lastModified": 1731533236,
|
|
9
|
+
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
|
|
10
|
+
"owner": "numtide",
|
|
11
|
+
"repo": "flake-utils",
|
|
12
|
+
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
|
|
13
|
+
"type": "github"
|
|
14
|
+
},
|
|
15
|
+
"original": {
|
|
16
|
+
"owner": "numtide",
|
|
17
|
+
"repo": "flake-utils",
|
|
18
|
+
"type": "github"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"nixpkgs": {
|
|
22
|
+
"locked": {
|
|
23
|
+
"lastModified": 1736139540,
|
|
24
|
+
"narHash": "sha256-39Iclrd+9tPLmvuFVyoG63WnHZJ9kCOC6eRytRYLAWw=",
|
|
25
|
+
"owner": "NixOS",
|
|
26
|
+
"repo": "nixpkgs",
|
|
27
|
+
"rev": "8ab83a21276434aaf44969b8dd0bc0e65b97a240",
|
|
28
|
+
"type": "github"
|
|
29
|
+
},
|
|
30
|
+
"original": {
|
|
31
|
+
"owner": "NixOS",
|
|
32
|
+
"repo": "nixpkgs",
|
|
33
|
+
"rev": "8ab83a21276434aaf44969b8dd0bc0e65b97a240",
|
|
34
|
+
"type": "github"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"nixpkgs-matrix": {
|
|
38
|
+
"inputs": {
|
|
39
|
+
"nixpkgs": "nixpkgs"
|
|
40
|
+
},
|
|
41
|
+
"locked": {
|
|
42
|
+
"lastModified": 1736140072,
|
|
43
|
+
"narHash": "sha256-MgtcAA+xPldS0WlV16TjJ0qgFzGvKuGM9p+nPUxpUoA=",
|
|
44
|
+
"owner": "MatrixAI",
|
|
45
|
+
"repo": "nixpkgs-matrix",
|
|
46
|
+
"rev": "029084026bc4a35bce81bac898aa695f41993e18",
|
|
47
|
+
"type": "github"
|
|
48
|
+
},
|
|
49
|
+
"original": {
|
|
50
|
+
"id": "nixpkgs-matrix",
|
|
51
|
+
"type": "indirect"
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
"root": {
|
|
55
|
+
"inputs": {
|
|
56
|
+
"flake-utils": "flake-utils",
|
|
57
|
+
"nixpkgs-matrix": "nixpkgs-matrix"
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
"systems": {
|
|
61
|
+
"locked": {
|
|
62
|
+
"lastModified": 1681028828,
|
|
63
|
+
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
|
64
|
+
"owner": "nix-systems",
|
|
65
|
+
"repo": "default",
|
|
66
|
+
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
|
67
|
+
"type": "github"
|
|
68
|
+
},
|
|
69
|
+
"original": {
|
|
70
|
+
"owner": "nix-systems",
|
|
71
|
+
"repo": "default",
|
|
72
|
+
"type": "github"
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
"root": "root",
|
|
77
|
+
"version": 7
|
|
78
|
+
}
|
package/jest.config.mjs
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import url from 'node:url';
|
|
3
|
+
import tsconfigJSON from './tsconfig.json' assert { type: "json" };
|
|
4
|
+
|
|
5
|
+
const projectPath = path.dirname(url.fileURLToPath(import.meta.url));
|
|
6
|
+
|
|
7
|
+
// Global variables that are shared across the jest worker pool
|
|
8
|
+
// These variables must be static and serializable
|
|
9
|
+
const globals = {
|
|
10
|
+
// Absolute directory to the project root
|
|
11
|
+
projectDir: projectPath,
|
|
12
|
+
// Absolute directory to the test root
|
|
13
|
+
testDir: path.join(projectPath, 'tests'),
|
|
14
|
+
// Default asynchronous test timeout
|
|
15
|
+
defaultTimeout: 20000,
|
|
16
|
+
// Timeouts rely on setTimeout which takes 32 bit numbers
|
|
17
|
+
maxTimeout: Math.pow(2, 31) - 1,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// The `globalSetup` and `globalTeardown` cannot access the `globals`
|
|
21
|
+
// They run in their own process context
|
|
22
|
+
// They can however receive the process environment
|
|
23
|
+
// Use `process.env` to set variables
|
|
24
|
+
|
|
25
|
+
const config = {
|
|
26
|
+
testEnvironment: 'node',
|
|
27
|
+
verbose: true,
|
|
28
|
+
collectCoverage: false,
|
|
29
|
+
cacheDirectory: '<rootDir>/tmp/jest',
|
|
30
|
+
coverageDirectory: '<rootDir>/tmp/coverage',
|
|
31
|
+
roots: ['<rootDir>/tests'],
|
|
32
|
+
testMatch: ['**/?(*.)+(spec|test|unit.test).+(ts|tsx|js|jsx)'],
|
|
33
|
+
transform: {
|
|
34
|
+
"^.+\\.(t|j)sx?$": [
|
|
35
|
+
"@swc/jest",
|
|
36
|
+
{
|
|
37
|
+
jsc: {
|
|
38
|
+
parser: {
|
|
39
|
+
syntax: "typescript",
|
|
40
|
+
tsx: true,
|
|
41
|
+
decorators: tsconfigJSON.compilerOptions.experimentalDecorators,
|
|
42
|
+
dynamicImport: true,
|
|
43
|
+
},
|
|
44
|
+
target: tsconfigJSON.compilerOptions.target.toLowerCase(),
|
|
45
|
+
keepClassNames: true,
|
|
46
|
+
},
|
|
47
|
+
}
|
|
48
|
+
],
|
|
49
|
+
},
|
|
50
|
+
reporters: [
|
|
51
|
+
'default',
|
|
52
|
+
['jest-junit', {
|
|
53
|
+
outputDirectory: '<rootDir>/tmp/junit',
|
|
54
|
+
classNameTemplate: '{classname}',
|
|
55
|
+
ancestorSeparator: ' > ',
|
|
56
|
+
titleTemplate: '{title}',
|
|
57
|
+
addFileAttribute: 'true',
|
|
58
|
+
reportTestSuiteErrors: 'true',
|
|
59
|
+
}],
|
|
60
|
+
],
|
|
61
|
+
collectCoverageFrom: ['src/**/*.{ts,tsx,js,jsx}', '!src/**/*.d.ts'],
|
|
62
|
+
coverageReporters: ['text', 'cobertura'],
|
|
63
|
+
globals,
|
|
64
|
+
// Global setup script executed once before all test files
|
|
65
|
+
globalSetup: '<rootDir>/tests/globalSetup.ts',
|
|
66
|
+
// Global teardown script executed once after all test files
|
|
67
|
+
globalTeardown: '<rootDir>/tests/globalTeardown.ts',
|
|
68
|
+
// Setup files are executed before each test file
|
|
69
|
+
// Can access globals
|
|
70
|
+
setupFiles: ['<rootDir>/tests/setup.ts'],
|
|
71
|
+
// Setup files after env are executed before each test file
|
|
72
|
+
// after the jest test environment is installed
|
|
73
|
+
// Can access globals
|
|
74
|
+
setupFilesAfterEnv: [
|
|
75
|
+
'jest-extended',
|
|
76
|
+
'<rootDir>/tests/setupAfterEnv.ts'
|
|
77
|
+
],
|
|
78
|
+
moduleNameMapper: {
|
|
79
|
+
"^(\\.{1,2}/.*)\\.js$": "$1",
|
|
80
|
+
},
|
|
81
|
+
extensionsToTreatAsEsm: ['.ts', '.tsx', '.mts'],
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export default config;
|
package/package.json
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@matrixai/lint",
|
|
3
|
+
"version": "0.0.2-0",
|
|
4
|
+
"author": "Roger Qiu",
|
|
5
|
+
"description": "Org wide custom eslint rules",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/MatrixAI/js-eslint.git"
|
|
10
|
+
},
|
|
11
|
+
"type": "module",
|
|
12
|
+
"exports": {
|
|
13
|
+
"./config": {
|
|
14
|
+
"import": "./dist/configs/matrixai-config-bundle.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"imports": {
|
|
18
|
+
"#*": "./dist/*"
|
|
19
|
+
},
|
|
20
|
+
"./package.json": "./package.json",
|
|
21
|
+
"bin": {
|
|
22
|
+
"matrixai-lint": "./dist/bin/lint.js"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"prepare": "tsc -p ./tsconfig.build.json",
|
|
26
|
+
"build": "shx rm -rf ./dist && tsc -p ./tsconfig.build.json && shx chmod +x dist/bin/lint.js",
|
|
27
|
+
"postversion": "npm install --package-lock-only --ignore-scripts --silent",
|
|
28
|
+
"tsx": "tsx",
|
|
29
|
+
"lint": "test -f ./dist/bin/lint.js || npm run build && ./dist/bin/lint.js",
|
|
30
|
+
"lintfix": "sh -c 'test -f ./dist/bin/lint.js || npm run build && ./dist/bin/lint.js --fix'",
|
|
31
|
+
"lint-shell": "find ./src ./tests ./scripts -type f -regextype posix-extended -regex '.*\\.(sh)' -exec shellcheck {} +",
|
|
32
|
+
"docs": "shx rm -rf ./docs && typedoc --entryPointStrategy expand --gitRevision master --tsconfig ./tsconfig.build.json --out ./docs src",
|
|
33
|
+
"test": "node ./scripts/test.mjs"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@eslint/compat": "^1.2.5",
|
|
37
|
+
"@eslint/js": "^9.16.0",
|
|
38
|
+
"@swc/core": "1.3.82",
|
|
39
|
+
"@swc/jest": "^0.2.29",
|
|
40
|
+
"@types/jest": "^29.5.2",
|
|
41
|
+
"@types/node": "^20.5.7",
|
|
42
|
+
"@typescript-eslint/eslint-plugin": "^8.27.0",
|
|
43
|
+
"@typescript-eslint/parser": "^8.27.0",
|
|
44
|
+
"@typescript-eslint/utils": "^8.26.1",
|
|
45
|
+
"eslint": "^9.18.0",
|
|
46
|
+
"eslint-config-prettier": "^9.1.0",
|
|
47
|
+
"eslint-plugin-import": "^2.31.0",
|
|
48
|
+
"eslint-plugin-prettier": "^5.2.1",
|
|
49
|
+
"eslint-plugin-jsx-a11y": "^6.10.2",
|
|
50
|
+
"eslint-plugin-react": "^7.37.4",
|
|
51
|
+
"eslint-plugin-react-hooks": "^5.1.0",
|
|
52
|
+
"eslint-plugin-tailwindcss": "^3.18.0",
|
|
53
|
+
"@eslint/eslintrc": "^3.2.0",
|
|
54
|
+
"jest": "^29.6.2",
|
|
55
|
+
"jest-extended": "^4.0.2",
|
|
56
|
+
"jest-junit": "^16.0.0",
|
|
57
|
+
"prettier": "^3.0.0",
|
|
58
|
+
"shx": "^0.3.4",
|
|
59
|
+
"tsconfig-paths": "^3.9.0",
|
|
60
|
+
"tsx": "^3.12.7",
|
|
61
|
+
"typedoc": "^0.24.8",
|
|
62
|
+
"typescript": "^5.1.6"
|
|
63
|
+
},
|
|
64
|
+
"peerDependencies": {
|
|
65
|
+
"eslint": ">=9.0.0"
|
|
66
|
+
}
|
|
67
|
+
}
|