@tsslint/config 2.0.7 → 3.0.0-alpha.1
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/bin/tsslint-docgen.js +98 -0
- package/index.d.ts +3 -0
- package/index.js +3 -0
- package/lib/eslint-gen.d.ts +4 -0
- package/lib/eslint-gen.js +302 -0
- package/lib/eslint-types.d.ts +4667 -0
- package/lib/eslint-types.js +3 -0
- package/lib/eslint.d.ts +27 -0
- package/lib/eslint.js +122 -0
- package/lib/plugins/category.js +1 -1
- package/lib/plugins/ignore.js +3 -3
- package/lib/tsl.d.ts +3 -0
- package/lib/tsl.js +70 -0
- package/lib/tslint-gen.d.ts +4 -0
- package/lib/tslint-gen.js +299 -0
- package/lib/tslint-types.d.ts +3793 -0
- package/lib/tslint-types.js +3 -0
- package/lib/tslint.d.ts +27 -0
- package/lib/tslint.js +167 -0
- package/package.json +29 -4
package/lib/tslint.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type * as TSSLint from '@tsslint/types';
|
|
2
|
+
import type { TSLintRulesConfig } from './tslint-types.js';
|
|
3
|
+
type Severity = boolean | 'error' | 'warn';
|
|
4
|
+
/**
|
|
5
|
+
* Converts a TSLint rules configuration to TSSLint rules.
|
|
6
|
+
*
|
|
7
|
+
* ⚠️ **Type definitions not generated**
|
|
8
|
+
*
|
|
9
|
+
* Please add `@tsslint/config` to `pnpm.onlyBuiltDependencies` in your `package.json` to allow the postinstall script to run.
|
|
10
|
+
*
|
|
11
|
+
* ```json
|
|
12
|
+
* {
|
|
13
|
+
* "pnpm": {
|
|
14
|
+
* "onlyBuiltDependencies": ["@tsslint/config"]
|
|
15
|
+
* }
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* After that, run `pnpm install` again to generate type definitions.
|
|
20
|
+
*
|
|
21
|
+
* If the type definitions become outdated, please run `npx tsslint-docgen` to update them.
|
|
22
|
+
*/
|
|
23
|
+
export declare function importTSLintRules(config: {
|
|
24
|
+
[K in keyof TSLintRulesConfig]: Severity | [Severity, ...TSLintRulesConfig[K]];
|
|
25
|
+
}): Promise<TSSLint.Rules>;
|
|
26
|
+
export declare function getTSLintRulesDirectories(): [string, string][];
|
|
27
|
+
export {};
|
package/lib/tslint.js
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.importTSLintRules = importTSLintRules;
|
|
4
|
+
exports.getTSLintRulesDirectories = getTSLintRulesDirectories;
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
const path = require("path");
|
|
7
|
+
const noop = () => { };
|
|
8
|
+
/**
|
|
9
|
+
* Converts a TSLint rules configuration to TSSLint rules.
|
|
10
|
+
*
|
|
11
|
+
* ⚠️ **Type definitions not generated**
|
|
12
|
+
*
|
|
13
|
+
* Please add `@tsslint/config` to `pnpm.onlyBuiltDependencies` in your `package.json` to allow the postinstall script to run.
|
|
14
|
+
*
|
|
15
|
+
* ```json
|
|
16
|
+
* {
|
|
17
|
+
* "pnpm": {
|
|
18
|
+
* "onlyBuiltDependencies": ["@tsslint/config"]
|
|
19
|
+
* }
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* After that, run `pnpm install` again to generate type definitions.
|
|
24
|
+
*
|
|
25
|
+
* If the type definitions become outdated, please run `npx tsslint-docgen` to update them.
|
|
26
|
+
*/
|
|
27
|
+
async function importTSLintRules(config) {
|
|
28
|
+
const rules = {};
|
|
29
|
+
const rulesDirectories = getTSLintRulesDirectories();
|
|
30
|
+
for (const [ruleName, severityOrOptions] of Object.entries(config)) {
|
|
31
|
+
let severity;
|
|
32
|
+
let options;
|
|
33
|
+
if (Array.isArray(severityOrOptions)) {
|
|
34
|
+
[severity, ...options] = severityOrOptions;
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
severity = severityOrOptions;
|
|
38
|
+
options = [];
|
|
39
|
+
}
|
|
40
|
+
if (!severity) {
|
|
41
|
+
rules[ruleName] = noop;
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
const ruleModule = await loadTSLintRule(ruleName, rulesDirectories);
|
|
45
|
+
if (!ruleModule) {
|
|
46
|
+
throw new Error(`Failed to resolve TSLint rule "${ruleName}".`);
|
|
47
|
+
}
|
|
48
|
+
rules[ruleName] = convertRule(ruleModule, options, severity === 'error'
|
|
49
|
+
? 1
|
|
50
|
+
: severity === 'warn'
|
|
51
|
+
? 0
|
|
52
|
+
: 3);
|
|
53
|
+
}
|
|
54
|
+
return rules;
|
|
55
|
+
}
|
|
56
|
+
function getTSLintRulesDirectories() {
|
|
57
|
+
const directories = [];
|
|
58
|
+
let dir = __dirname;
|
|
59
|
+
while (true) {
|
|
60
|
+
const tslintJsonPath = path.join(dir, 'tslint.json');
|
|
61
|
+
if (fs.existsSync(tslintJsonPath)) {
|
|
62
|
+
try {
|
|
63
|
+
let content = fs.readFileSync(tslintJsonPath, 'utf8');
|
|
64
|
+
// Remove comments
|
|
65
|
+
content = content.replace(/\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/gm, '$1');
|
|
66
|
+
const tslintJson = JSON.parse(content);
|
|
67
|
+
if (tslintJson.rulesDirectory) {
|
|
68
|
+
const rulesDirs = Array.isArray(tslintJson.rulesDirectory)
|
|
69
|
+
? tslintJson.rulesDirectory
|
|
70
|
+
: [tslintJson.rulesDirectory];
|
|
71
|
+
for (const rulesDir of rulesDirs) {
|
|
72
|
+
directories.push([rulesDir, path.resolve(dir, rulesDir)]);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
catch (e) {
|
|
77
|
+
// Ignore parse errors
|
|
78
|
+
}
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
const parentDir = path.resolve(dir, '..');
|
|
82
|
+
if (parentDir === dir) {
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
dir = parentDir;
|
|
86
|
+
}
|
|
87
|
+
return directories;
|
|
88
|
+
}
|
|
89
|
+
async function loadTSLintRule(ruleName, rulesDirectories) {
|
|
90
|
+
const camelCaseName = ruleName.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
|
|
91
|
+
const ruleFileName = `${camelCaseName.charAt(0).toUpperCase() + camelCaseName.slice(1)}Rule.js`;
|
|
92
|
+
for (const [, rulesDir] of rulesDirectories) {
|
|
93
|
+
const rulePath = path.resolve(rulesDir, ruleFileName);
|
|
94
|
+
if (fs.existsSync(rulePath)) {
|
|
95
|
+
const mod = require(rulePath);
|
|
96
|
+
return mod.Rule;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
let dir = __dirname;
|
|
100
|
+
while (true) {
|
|
101
|
+
const nodeModulesDir = path.join(dir, 'node_modules');
|
|
102
|
+
if (fs.existsSync(nodeModulesDir)) {
|
|
103
|
+
const tslintDir = path.join(nodeModulesDir, 'tslint', 'lib', 'rules');
|
|
104
|
+
if (fs.existsSync(tslintDir)) {
|
|
105
|
+
const rulePath = path.join(tslintDir, ruleFileName);
|
|
106
|
+
if (fs.existsSync(rulePath)) {
|
|
107
|
+
const mod = require(rulePath);
|
|
108
|
+
return mod.Rule;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
const parentDir = path.resolve(dir, '..');
|
|
113
|
+
if (parentDir === dir) {
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
dir = parentDir;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
function convertRule(Rule, ruleArguments = [], category = 3) {
|
|
120
|
+
const rule = new Rule({
|
|
121
|
+
ruleName: Rule.metadata?.ruleName ?? 'unknown',
|
|
122
|
+
ruleArguments,
|
|
123
|
+
ruleSeverity: 'warning',
|
|
124
|
+
disabledIntervals: [],
|
|
125
|
+
});
|
|
126
|
+
return ({ typescript: ts, file, report, ...ctx }) => {
|
|
127
|
+
if (Rule.metadata?.typescriptOnly) {
|
|
128
|
+
const scriptKind = file.scriptKind;
|
|
129
|
+
if (scriptKind === ts.ScriptKind.JS || scriptKind === ts.ScriptKind.JSX) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
const failures = 'applyWithProgram' in rule
|
|
134
|
+
? rule.applyWithProgram(file, ctx.program)
|
|
135
|
+
: rule.apply(file);
|
|
136
|
+
for (const failure of failures) {
|
|
137
|
+
const reporter = report(failure.getFailure(), failure.getStartPosition().getPosition(), failure.getEndPosition().getPosition()).at(new Error(), Number.MAX_VALUE);
|
|
138
|
+
if (category === 0) {
|
|
139
|
+
reporter.asWarning();
|
|
140
|
+
}
|
|
141
|
+
else if (category === 1) {
|
|
142
|
+
reporter.asError();
|
|
143
|
+
}
|
|
144
|
+
else if (category === 2) {
|
|
145
|
+
reporter.asSuggestion();
|
|
146
|
+
}
|
|
147
|
+
if (failure.hasFix()) {
|
|
148
|
+
const ruleName = Rule.metadata?.ruleName;
|
|
149
|
+
reporter.withFix(ruleName ? `Fix with ${ruleName}` : 'Fix', () => {
|
|
150
|
+
const fix = failure.getFix();
|
|
151
|
+
const replaces = Array.isArray(fix) ? fix : fix ? [fix] : [];
|
|
152
|
+
return [{
|
|
153
|
+
fileName: file.fileName,
|
|
154
|
+
textChanges: replaces.map(replace => ({
|
|
155
|
+
newText: replace.text,
|
|
156
|
+
span: {
|
|
157
|
+
start: replace.start,
|
|
158
|
+
length: replace.length,
|
|
159
|
+
},
|
|
160
|
+
})),
|
|
161
|
+
}];
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
//# sourceMappingURL=tslint.js.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsslint/config",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-alpha.1",
|
|
4
4
|
"license": "MIT",
|
|
5
|
+
"engines": {
|
|
6
|
+
"node": ">=22.6.0"
|
|
7
|
+
},
|
|
8
|
+
"bin": {
|
|
9
|
+
"tsslint-docgen": "./bin/tsslint-docgen.js"
|
|
10
|
+
},
|
|
5
11
|
"files": [
|
|
6
12
|
"**/*.js",
|
|
7
13
|
"**/*.d.ts"
|
|
@@ -11,10 +17,29 @@
|
|
|
11
17
|
"url": "https://github.com/johnsoncodehk/tsslint.git",
|
|
12
18
|
"directory": "packages/config"
|
|
13
19
|
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"postinstall": "tsslint-docgen"
|
|
22
|
+
},
|
|
14
23
|
"dependencies": {
|
|
15
|
-
"@tsslint/types": "
|
|
24
|
+
"@tsslint/types": "3.0.0-alpha.1",
|
|
16
25
|
"minimatch": "^10.0.1",
|
|
17
26
|
"ts-api-utils": "^2.0.0"
|
|
18
27
|
},
|
|
19
|
-
"
|
|
20
|
-
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@tsslint/compat-eslint": "3.0.0-alpha.1",
|
|
30
|
+
"tslint": "^6.1.3"
|
|
31
|
+
},
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"@tsslint/compat-eslint": "3.0.0-alpha.0",
|
|
34
|
+
"tsl": "^1.0.28"
|
|
35
|
+
},
|
|
36
|
+
"peerDependenciesMeta": {
|
|
37
|
+
"@tsslint/compat-eslint": {
|
|
38
|
+
"optional": true
|
|
39
|
+
},
|
|
40
|
+
"tsl": {
|
|
41
|
+
"optional": true
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"gitHead": "eacd205927cda18d084e78cc21115578792f3955"
|
|
45
|
+
}
|