@tsslint/core 1.0.15 → 1.0.16

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 (3) hide show
  1. package/index.js +89 -15
  2. package/lib/watch.js +1 -2
  3. package/package.json +3 -3
package/index.js CHANGED
@@ -45,15 +45,63 @@ function createLinter(ctx, config, withStack) {
45
45
  const fileRefactors = new Map();
46
46
  const sourceFiles = new Map();
47
47
  const plugins = (config.plugins ?? []).map(plugin => plugin(ctx));
48
+ const includes = [];
48
49
  const excludes = [];
49
- for (let exclude of config.exclude ?? []) {
50
+ for (const include of config.include ?? []) {
50
51
  const basePath = path.dirname(ctx.configFile);
51
- excludes.push(path.resolve(basePath, exclude));
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)]);
52
57
  }
53
58
  return {
54
59
  lint(fileName) {
55
- if (excludes.some(pattern => minimatch.minimatch(fileName, pattern))) {
56
- return [];
60
+ let diagnostics = [];
61
+ let debugInfo;
62
+ if (config.debug) {
63
+ debugInfo = {
64
+ category: ts.DiagnosticCategory.Message,
65
+ code: 'debug',
66
+ messageText: '- Config: ' + ctx.configFile + '\n',
67
+ file: ctx.languageService.getProgram().getSourceFile(fileName),
68
+ start: 0,
69
+ length: 0,
70
+ source: 'tsslint',
71
+ relatedInformation: [],
72
+ };
73
+ diagnostics.push(debugInfo);
74
+ }
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 {
102
+ if (debugInfo) {
103
+ debugInfo.messageText += '- Included: ✅ (no include patterns)\n';
104
+ }
57
105
  }
58
106
  const sourceFile = ctx.languageService.getProgram()?.getSourceFile(fileName);
59
107
  if (!sourceFile) {
@@ -70,29 +118,52 @@ function createLinter(ctx, config, withStack) {
70
118
  const rules = getFileRules(sourceFile.fileName);
71
119
  const fixes = getFileFixes(sourceFile.fileName);
72
120
  const refactors = getFileRefactors(sourceFile.fileName);
73
- let diagnostics = [];
74
121
  let currentRuleId;
122
+ let currentIssues = 0;
123
+ let currentFixes = 0;
124
+ let currentRefactors = 0;
75
125
  fixes.clear();
76
126
  refactors.clear();
127
+ if (debugInfo) {
128
+ debugInfo.messageText += '- Rules:\n';
129
+ }
77
130
  for (const [id, rule] of Object.entries(rules)) {
78
131
  if (token?.isCancellationRequested()) {
79
132
  break;
80
133
  }
81
134
  currentRuleId = id;
135
+ currentIssues = 0;
136
+ currentFixes = 0;
137
+ currentRefactors = 0;
138
+ const start = Date.now();
82
139
  try {
83
140
  rule(rulesContext);
141
+ if (debugInfo) {
142
+ const time = Date.now() - start;
143
+ debugInfo.messageText += ` - ${id}`;
144
+ const details = [];
145
+ if (currentIssues) {
146
+ details.push(`${currentIssues} issues`);
147
+ }
148
+ if (currentFixes) {
149
+ details.push(`${currentFixes} fixes`);
150
+ }
151
+ if (currentRefactors) {
152
+ details.push(`${currentRefactors} refactors`);
153
+ }
154
+ if (time) {
155
+ details.push(`${time}ms`);
156
+ }
157
+ if (details.length) {
158
+ debugInfo.messageText += ` (${details.join(', ')})`;
159
+ }
160
+ debugInfo.messageText += '\n';
161
+ }
84
162
  }
85
163
  catch (err) {
86
- diagnostics.push({
87
- category: ts.DiagnosticCategory.Error,
88
- code: id,
89
- messageText: String(err),
90
- file: sourceFile,
91
- start: 0,
92
- length: 0,
93
- source: 'tsslint',
94
- relatedInformation: [],
95
- });
164
+ if (debugInfo) {
165
+ debugInfo.messageText += ` - ${id} (❌ ${err && typeof err === 'object' && 'stack' in err ? err.stack : String(err)}})\n`;
166
+ }
96
167
  }
97
168
  }
98
169
  for (const plugin of plugins) {
@@ -152,6 +223,7 @@ function createLinter(ctx, config, withStack) {
152
223
  }
153
224
  }
154
225
  diagnostics.push(error);
226
+ currentIssues++;
155
227
  return {
156
228
  withDeprecated() {
157
229
  error.reportsDeprecated = true;
@@ -162,6 +234,7 @@ function createLinter(ctx, config, withStack) {
162
234
  return this;
163
235
  },
164
236
  withFix(title, getEdits) {
237
+ currentFixes++;
165
238
  if (!fixes.has(currentRuleId)) {
166
239
  fixes.set(currentRuleId, []);
167
240
  }
@@ -175,6 +248,7 @@ function createLinter(ctx, config, withStack) {
175
248
  return this;
176
249
  },
177
250
  withRefactor(title, getEdits) {
251
+ currentRefactors++;
178
252
  if (!refactors.has(currentRuleId)) {
179
253
  refactors.set(currentRuleId, []);
180
254
  }
package/lib/watch.js CHANGED
@@ -13,8 +13,7 @@ async function watchConfigFile(configFilePath, onBuild, watch = true, createHash
13
13
  let config;
14
14
  if (!result.errors.length) {
15
15
  try {
16
- config = (await import(outFile)).default;
17
- delete require.cache[outFile];
16
+ config = (await import(outFile + '?time=' + Date.now())).default;
18
17
  }
19
18
  catch (e) {
20
19
  result.errors.push({ text: String(e) });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsslint/core",
3
- "version": "1.0.15",
3
+ "version": "1.0.16",
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.15",
15
+ "@tsslint/types": "1.0.16",
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": "58de9acb2cb7a1d7e93a5fb983fec54bf083f7b9"
21
+ "gitHead": "e430814fd394da5afbcd3157d02c246592162f75"
22
22
  }