@tsslint/core 1.0.16 → 1.0.17

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/index.d.ts CHANGED
@@ -3,7 +3,7 @@ export * from './lib/watch';
3
3
  import type { Config, ProjectContext } from '@tsslint/types';
4
4
  import type * as ts from 'typescript';
5
5
  export type Linter = ReturnType<typeof createLinter>;
6
- export declare function createLinter(ctx: ProjectContext, config: Config, withStack: boolean): {
6
+ export declare function createLinter(ctx: ProjectContext, config: Config | Config[], withStack: boolean): {
7
7
  lint(fileName: string): ts.DiagnosticWithLocation[];
8
8
  hasCodeFixes(fileName: string): boolean;
9
9
  getCodeFixes(fileName: string, start: number, end: number, diagnostics?: ts.Diagnostic[]): ts.CodeFixAction[];
package/index.js CHANGED
@@ -44,24 +44,26 @@ function createLinter(ctx, config, withStack) {
44
44
  const fileFixes = new Map();
45
45
  const fileRefactors = new Map();
46
46
  const sourceFiles = new Map();
47
- const plugins = (config.plugins ?? []).map(plugin => plugin(ctx));
48
- const includes = [];
49
- const excludes = [];
50
- for (const include of config.include ?? []) {
51
- const basePath = path.dirname(ctx.configFile);
52
- includes.push([include, path.resolve(basePath, include)]);
53
- }
54
- for (const exclude of config.exclude ?? []) {
55
- const basePath = path.dirname(ctx.configFile);
56
- excludes.push([exclude, path.resolve(basePath, exclude)]);
57
- }
47
+ const basePath = path.dirname(ctx.configFile);
48
+ const configs = (Array.isArray(config) ? config : [config])
49
+ .map(config => ({
50
+ config,
51
+ includes: (config.include ?? []).map(include => {
52
+ return path.resolve(basePath, include);
53
+ }),
54
+ excludes: (config.exclude ?? []).map(exclude => {
55
+ return path.resolve(basePath, exclude);
56
+ }),
57
+ }));
58
+ const plugins = configs.map(({ config }) => config.plugins ?? []).flat().map(plugin => plugin(ctx));
59
+ const debug = configs.some(({ config }) => config.debug);
58
60
  return {
59
61
  lint(fileName) {
60
62
  let diagnostics = [];
61
63
  let debugInfo;
62
- if (config.debug) {
64
+ if (debug) {
63
65
  debugInfo = {
64
- category: ts.DiagnosticCategory.Message,
66
+ category: ts.DiagnosticCategory.Suggestion,
65
67
  code: 'debug',
66
68
  messageText: '- Config: ' + ctx.configFile + '\n',
67
69
  file: ctx.languageService.getProgram().getSourceFile(fileName),
@@ -72,36 +74,12 @@ function createLinter(ctx, config, withStack) {
72
74
  };
73
75
  diagnostics.push(debugInfo);
74
76
  }
75
- for (const [exclude, pattern] of excludes) {
76
- if (minimatch.minimatch(fileName, pattern)) {
77
- if (debugInfo) {
78
- debugInfo.messageText += '- Included: ❌ (via ' + JSON.stringify({ exclude: [exclude] }) + ')\n';
79
- }
80
- return diagnostics;
81
- }
82
- }
83
- if (includes.length) {
84
- let included = false;
85
- for (const [include, pattern] of includes) {
86
- if (minimatch.minimatch(fileName, pattern)) {
87
- included = true;
88
- if (debugInfo) {
89
- debugInfo.messageText += '- Included: ✅ (via ' + JSON.stringify({ include: [include] }) + ')\n';
90
- }
91
- break;
92
- }
93
- }
94
- if (!included) {
95
- if (debugInfo) {
96
- debugInfo.messageText += '- Included: ❌ (not included in any include patterns)\n';
97
- }
98
- return diagnostics;
99
- }
100
- }
101
- else {
77
+ const rules = getFileRules(fileName);
78
+ if (!rules || !Object.keys(rules).length) {
102
79
  if (debugInfo) {
103
- debugInfo.messageText += '- Included: (no include patterns)\n';
80
+ debugInfo.messageText += '- Rules: (no rules)\n';
104
81
  }
82
+ return diagnostics;
105
83
  }
106
84
  const sourceFile = ctx.languageService.getProgram()?.getSourceFile(fileName);
107
85
  if (!sourceFile) {
@@ -115,7 +93,6 @@ function createLinter(ctx, config, withStack) {
115
93
  reportSuggestion,
116
94
  };
117
95
  const token = ctx.languageServiceHost.getCancellationToken?.();
118
- const rules = getFileRules(sourceFile.fileName);
119
96
  const fixes = getFileFixes(sourceFile.fileName);
120
97
  const refactors = getFileRefactors(sourceFile.fileName);
121
98
  let currentRuleId;
@@ -265,7 +242,9 @@ function createLinter(ctx, config, withStack) {
265
242
  }
266
243
  function pushRelatedInformation(error, stack) {
267
244
  if (stack.fileName && stack.lineNumber !== undefined && stack.columnNumber !== undefined) {
268
- let fileName = stack.fileName.replace(/\\/g, '/');
245
+ let fileName = stack.fileName
246
+ .replace(/\\/g, '/')
247
+ .split('?time=')[0];
269
248
  if (fileName.startsWith('file://')) {
270
249
  fileName = fileName.substring('file://'.length);
271
250
  }
@@ -366,7 +345,19 @@ function createLinter(ctx, config, withStack) {
366
345
  function getFileRules(fileName) {
367
346
  let rules = fileRules.get(fileName);
368
347
  if (!rules) {
369
- rules = { ...config.rules };
348
+ rules = {};
349
+ for (const { config, includes, excludes } of configs) {
350
+ if (!config.rules) {
351
+ continue;
352
+ }
353
+ if (excludes.some(pattern => minimatch.minimatch(fileName, pattern))) {
354
+ continue;
355
+ }
356
+ if (includes.length && !includes.some(pattern => minimatch.minimatch(fileName, pattern))) {
357
+ continue;
358
+ }
359
+ rules = { ...rules, ...config.rules };
360
+ }
370
361
  for (const plugin of plugins) {
371
362
  if (plugin.resolveRules) {
372
363
  rules = plugin.resolveRules(fileName, rules);
package/lib/build.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  import type { Config } from '@tsslint/config';
2
- export declare function buildConfigFile(configFilePath: string, createHash?: (path: string) => string, logger?: Pick<typeof console, 'log' | 'warn' | 'error'>): Promise<Config>;
2
+ export declare function buildConfigFile(configFilePath: string, createHash?: (path: string) => string, logger?: Pick<typeof console, 'log' | 'warn' | 'error'>): Promise<Config | Config[]>;
package/lib/watch.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import esbuild = require('esbuild');
2
2
  import type { Config } from '@tsslint/config';
3
- export declare function watchConfigFile(configFilePath: string, onBuild: (config: Config | undefined, result: esbuild.BuildResult) => void, watch?: boolean, createHash?: (path: string) => string, logger?: Pick<typeof console, 'log' | 'warn' | 'error'>): Promise<esbuild.BuildContext<{
3
+ export declare function watchConfigFile(configFilePath: string, onBuild: (config: Config | Config[] | undefined, result: esbuild.BuildResult) => void, watch?: boolean, createHash?: (path: string) => string, logger?: Pick<typeof console, 'log' | 'warn' | 'error'>): Promise<esbuild.BuildContext<{
4
4
  entryPoints: string[];
5
5
  bundle: true;
6
6
  sourcemap: true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsslint/core",
3
- "version": "1.0.16",
3
+ "version": "1.0.17",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "**/*.js",
@@ -12,11 +12,11 @@
12
12
  "directory": "packages/core"
13
13
  },
14
14
  "dependencies": {
15
- "@tsslint/types": "1.0.16",
15
+ "@tsslint/types": "1.0.17",
16
16
  "error-stack-parser": "^2.1.4",
17
17
  "esbuild": "^0.23.0",
18
18
  "minimatch": "^10.0.1",
19
19
  "source-map-support": "^0.5.21"
20
20
  },
21
- "gitHead": "e430814fd394da5afbcd3157d02c246592162f75"
21
+ "gitHead": "5ffa59ffc098b272ff18579d9fc57f1658978a5e"
22
22
  }