Skip to content

Commit df98c15

Browse files
committed
refactor(domains): flatten plugins and restore dist config path
- Flatten lint domain engine and plugin modules into top level domain folders. - Consolidate shared domain types and utilities and update domain tests. - Restore ESLint default config resolution to compiled eslint.js path.
1 parent 948fe75 commit df98c15

20 files changed

Lines changed: 1274 additions & 1223 deletions

src/LintDomainPluginBase.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import type {
2+
LintDomain,
3+
LintDomainDetection,
4+
LintDomainEngineContext,
5+
LintDomainPlugin,
6+
LintDomainPluginResult,
7+
} from './types.js';
8+
9+
function normalizeLogDetail(value: unknown): string {
10+
return String(value)
11+
.replace(/\r?\n+/g, ' | ')
12+
.trim();
13+
}
14+
15+
abstract class LintDomainPluginBase implements LintDomainPlugin {
16+
public abstract readonly domain: LintDomain;
17+
public abstract readonly description: string;
18+
19+
public abstract detect(
20+
context: LintDomainEngineContext,
21+
): Promise<LintDomainDetection> | LintDomainDetection;
22+
23+
public abstract run(
24+
context: LintDomainEngineContext,
25+
detection: LintDomainDetection,
26+
): Promise<LintDomainPluginResult> | LintDomainPluginResult;
27+
28+
protected normalizeLogDetail(value: unknown): string {
29+
return normalizeLogDetail(value);
30+
}
31+
}
32+
33+
export default LintDomainPluginBase;

src/bin/matrixai-lint.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import {
1414
evaluateLintDomains,
1515
runLintDomainDecisions,
1616
type LintDomainDecision,
17-
} from '../domains/index.js';
17+
} from '../domains.js';
18+
import * as eslintUtils from '../eslint/utils.js';
1819
import * as utils from '../utils.js';
1920

2021
const program = new Command();
@@ -179,7 +180,7 @@ async function main(argv = process.argv) {
179180
chosenConfig = absolutePath;
180181
}
181182
} else if (useUserConfig) {
182-
chosenConfig = utils.findUserESLintConfig();
183+
chosenConfig = eslintUtils.findUserESLintConfig();
183184
if (chosenConfig === undefined) {
184185
logger.warn(
185186
'--user-config given but no local ESLint config was found. Falling back to built-in config.',

src/configs/eslint.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import tsParser from '@typescript-eslint/parser';
88
import { FlatCompat } from '@eslint/eslintrc';
99
import { fixupPluginRules } from '@eslint/compat';
1010
import prettierOptions from './prettier.config.js';
11-
import matrixaiPlugin from '../plugins/eslint-plugin-matrixai.js';
11+
import noAliasedImportsRule from '../eslint/rules/no-aliased-imports.js';
1212
import { resolveLintConfig } from '../config.js';
1313

1414
const resolvedLintConfig = resolveLintConfig();
@@ -35,7 +35,11 @@ const config = [
3535
{
3636
plugins: {
3737
import: fixupPluginRules(_import),
38-
'@matrixai': matrixaiPlugin,
38+
'@matrixai': {
39+
rules: {
40+
'no-aliased-imports': noAliasedImportsRule,
41+
},
42+
},
3943
},
4044

4145
settings: {
Lines changed: 15 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,16 @@
1-
import type { LintDomain } from '../types.js';
2-
import type Logger from '@matrixai/logger';
3-
4-
type LintDomainEngineContext = {
5-
fix: boolean;
6-
logger: Logger;
7-
chosenConfig?: string;
8-
isConfigValid: boolean;
9-
eslintPatterns?: string[];
10-
shellPatterns?: string[];
11-
markdownPatterns?: string[];
12-
nixPatterns?: string[];
13-
};
14-
15-
type LintDomainAvailabilityKind = 'required' | 'optional';
16-
17-
type LintDomainDetection = {
18-
relevant: boolean;
19-
relevanceReason?: string;
20-
available: boolean;
21-
availabilityKind: LintDomainAvailabilityKind;
22-
unavailableReason?: string;
23-
matchedFiles?: string[];
24-
};
25-
26-
type LintDomainPluginResult = {
27-
hadFailure: boolean;
28-
};
29-
30-
type LintDomainSelectionSource =
31-
| 'default'
32-
| 'domain-flag'
33-
| 'target-flag'
34-
| 'unselected';
35-
36-
type LintDomainPlannedAction =
37-
| 'run'
38-
| 'skip-unselected'
39-
| 'skip-not-relevant'
40-
| 'skip-unavailable'
41-
| 'fail-unavailable'
42-
| 'fail-detection';
43-
44-
type LintDomainDecision = {
45-
domain: LintDomain;
46-
description: string;
47-
selected: boolean;
48-
explicitlyRequested: boolean;
49-
selectionSource: LintDomainSelectionSource;
50-
detection: LintDomainDetection | null;
51-
plannedAction: LintDomainPlannedAction;
52-
detectionError?: string;
53-
};
54-
55-
type LintDomainPlugin = {
56-
domain: LintDomain;
57-
description: string;
58-
detect:
59-
| ((context: LintDomainEngineContext) => Promise<LintDomainDetection>)
60-
| ((context: LintDomainEngineContext) => LintDomainDetection);
61-
run:
62-
| ((
63-
context: LintDomainEngineContext,
64-
detection: LintDomainDetection,
65-
) => Promise<LintDomainPluginResult>)
66-
| ((
67-
context: LintDomainEngineContext,
68-
detection: LintDomainDetection,
69-
) => LintDomainPluginResult);
70-
};
1+
import type {
2+
LintDomainAvailabilityKind,
3+
LintDomainDecision,
4+
LintDomainDetect,
5+
LintDomainDetection,
6+
LintDomain,
7+
LintDomainEngineContext,
8+
LintDomainPlannedAction,
9+
LintDomainPlugin,
10+
LintDomainPluginResult,
11+
LintDomainRun,
12+
LintDomainSelectionSource,
13+
} from './types.js';
7114

7215
function normalizeLogDetail(value: unknown): string {
7316
return String(value)
@@ -313,7 +256,9 @@ async function runLintDomains({
313256
}
314257

315258
export type {
259+
LintDomainDetect,
316260
LintDomainDecision,
261+
LintDomainRun,
317262
LintDomainPlannedAction,
318263
LintDomainSelectionSource,
319264
LintDomainAvailabilityKind,
Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { LintDomain, CLIOptions } from '../types.js';
1+
import type { LintDomain, CLIOptions } from './types.js';
22
import {
33
createLintDomainRegistry,
44
listLintDomains,
@@ -10,11 +10,11 @@ import {
1010
type LintDomainDecision,
1111
type LintDomainEngineContext,
1212
type LintDomainSelectionSource,
13-
} from './engine.js';
14-
import { createESLintDomainPlugin } from './eslint.js';
15-
import { createShellDomainPlugin } from './shell.js';
16-
import { createMarkdownDomainPlugin } from './markdown.js';
17-
import { createNixDomainPlugin } from './nix.js';
13+
} from './domainEngine.js';
14+
import ESLintDomainPlugin from './eslint/ESLintDomainPlugin.js';
15+
import ShellDomainPlugin from './shell/ShellDomainPlugin.js';
16+
import MarkdownDomainPlugin from './markdown/MarkdownDomainPlugin.js';
17+
import NixDomainPlugin from './nix/NixDomainPlugin.js';
1818

1919
const LINT_DOMAINS: LintDomain[] = ['eslint', 'shell', 'markdown', 'nix'];
2020

@@ -116,16 +116,10 @@ function createBuiltInDomainRegistry({
116116
prettierConfigPath: string;
117117
}): Map<LintDomain, LintDomainPlugin> {
118118
return createLintDomainRegistry([
119-
createESLintDomainPlugin(),
120-
createShellDomainPlugin({
121-
defaultSearchRoots: DEFAULT_SHELLCHECK_SEARCH_ROOTS,
122-
}),
123-
createMarkdownDomainPlugin({
124-
prettierConfigPath,
125-
}),
126-
createNixDomainPlugin({
127-
defaultSearchPatterns: DEFAULT_NIXFMT_SEARCH_PATTERNS,
128-
}),
119+
new ESLintDomainPlugin(),
120+
new ShellDomainPlugin(DEFAULT_SHELLCHECK_SEARCH_ROOTS),
121+
new MarkdownDomainPlugin(prettierConfigPath),
122+
new NixDomainPlugin(DEFAULT_NIXFMT_SEARCH_PATTERNS),
129123
]);
130124
}
131125

src/domains/eslint.ts

Lines changed: 0 additions & 130 deletions
This file was deleted.

0 commit comments

Comments
 (0)