@tsslint/core 1.0.9 → 1.0.11

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.
Files changed (2) hide show
  1. package/index.js +26 -7
  2. package/package.json +4 -3
package/index.js CHANGED
@@ -2,6 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.applyTextChanges = exports.combineCodeFixes = exports.createLinter = void 0;
4
4
  const ErrorStackParser = require("error-stack-parser");
5
+ const path = require("path");
6
+ const minimatch = require("minimatch");
5
7
  function createLinter(ctx, config, withStack) {
6
8
  if (withStack) {
7
9
  require('source-map-support').install({
@@ -20,17 +22,20 @@ function createLinter(ctx, config, withStack) {
20
22
  });
21
23
  }
22
24
  const ts = ctx.typescript;
25
+ const fileRules = new Map();
23
26
  const fileFixes = new Map();
24
27
  const sourceFiles = new Map();
25
28
  const plugins = (config.plugins ?? []).map(plugin => plugin(ctx));
26
- let rules = { ...config.rules };
27
- for (const plugin of plugins) {
28
- if (plugin.resolveRules) {
29
- rules = plugin.resolveRules(rules);
30
- }
29
+ const excludes = [];
30
+ for (let exclude of config.exclude ?? []) {
31
+ const basePath = path.dirname(ctx.configFile);
32
+ excludes.push(path.resolve(basePath, exclude));
31
33
  }
32
34
  return {
33
35
  lint(fileName) {
36
+ if (excludes.some(pattern => minimatch.minimatch(fileName, pattern))) {
37
+ return [];
38
+ }
34
39
  const sourceFile = ctx.languageService.getProgram()?.getSourceFile(fileName);
35
40
  if (!sourceFile) {
36
41
  throw new Error(`No source file found for ${fileName}`);
@@ -43,6 +48,7 @@ function createLinter(ctx, config, withStack) {
43
48
  reportSuggestion,
44
49
  };
45
50
  const token = ctx.languageServiceHost.getCancellationToken?.();
51
+ const rules = getFileRules(sourceFile.fileName);
46
52
  const fixes = getFileFixes(sourceFile.fileName);
47
53
  let result = [];
48
54
  let currentRuleId;
@@ -56,13 +62,13 @@ function createLinter(ctx, config, withStack) {
56
62
  rule(rulesContext);
57
63
  }
58
64
  catch (err) {
59
- console.error(`An unexpected error occurred in rule "${id}" in file ${fileName}.`);
65
+ console.error(`An unexpected error occurred in rule "${id}" in file ${sourceFile.fileName}.`);
60
66
  console.error(err);
61
67
  }
62
68
  }
63
69
  for (const plugin of plugins) {
64
70
  if (plugin.resolveDiagnostics) {
65
- result = plugin.resolveDiagnostics(fileName, result);
71
+ result = plugin.resolveDiagnostics(sourceFile.fileName, result);
66
72
  }
67
73
  }
68
74
  return result;
@@ -192,6 +198,19 @@ function createLinter(ctx, config, withStack) {
192
198
  return result;
193
199
  },
194
200
  };
201
+ function getFileRules(fileName) {
202
+ let rules = fileRules.get(fileName);
203
+ if (!rules) {
204
+ rules = { ...config.rules };
205
+ for (const plugin of plugins) {
206
+ if (plugin.resolveRules) {
207
+ rules = plugin.resolveRules(fileName, rules);
208
+ }
209
+ }
210
+ fileRules.set(fileName, rules);
211
+ }
212
+ return rules;
213
+ }
195
214
  function getFileFixes(fileName) {
196
215
  if (!fileFixes.has(fileName)) {
197
216
  fileFixes.set(fileName, new Map());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsslint/core",
3
- "version": "1.0.9",
3
+ "version": "1.0.11",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "**/*.js",
@@ -13,10 +13,11 @@
13
13
  },
14
14
  "dependencies": {
15
15
  "error-stack-parser": "^2.1.4",
16
+ "minimatch": "^9.0.4",
16
17
  "source-map-support": "^0.5.21"
17
18
  },
18
19
  "devDependencies": {
19
- "@tsslint/config": "1.0.9"
20
+ "@tsslint/config": "1.0.11"
20
21
  },
21
- "gitHead": "8e531c2a5ad3589cdcb0be75d0cacee0e4184c85"
22
+ "gitHead": "5797507a1ef19b82bafa6f43cdf412905723374f"
22
23
  }