@tsslint/config 0.0.0
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 +6 -0
- package/index.js +25 -0
- package/lib/findConfigFile.d.ts +2 -0
- package/lib/findConfigFile.js +20 -0
- package/lib/loadConfig.d.ts +20 -0
- package/lib/loadConfig.js +56 -0
- package/lib/tslint.d.ts +5 -0
- package/lib/tslint.js +49 -0
- package/lib/types.d.ts +44 -0
- package/lib/types.js +3 -0
- package/package.json +22 -0
package/index.d.ts
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.defineConfig = void 0;
|
|
18
|
+
__exportStar(require("./lib/findConfigFile"), exports);
|
|
19
|
+
__exportStar(require("./lib/tslint"), exports);
|
|
20
|
+
__exportStar(require("./lib/types"), exports);
|
|
21
|
+
function defineConfig(config) {
|
|
22
|
+
return config;
|
|
23
|
+
}
|
|
24
|
+
exports.defineConfig = defineConfig;
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.findConfigFile = void 0;
|
|
4
|
+
const path = require("path");
|
|
5
|
+
function findConfigFile(dir) {
|
|
6
|
+
const dirs = [dir];
|
|
7
|
+
let upDir;
|
|
8
|
+
while ((upDir = path.resolve(dir, '..')) !== dirs[dirs.length - 1]) {
|
|
9
|
+
dirs.push(upDir);
|
|
10
|
+
dir = upDir;
|
|
11
|
+
}
|
|
12
|
+
for (const dir of dirs) {
|
|
13
|
+
try {
|
|
14
|
+
return require.resolve('./tsslint.config.ts', { paths: [dir] });
|
|
15
|
+
}
|
|
16
|
+
catch { }
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.findConfigFile = findConfigFile;
|
|
20
|
+
//# sourceMappingURL=findConfigFile.js.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Config } from './types';
|
|
2
|
+
import esbuild = require('/Users/johnsonchu/Desktop/GitHub/tsslint/node_modules/.pnpm/esbuild@0.19.9/node_modules/esbuild/lib/main.js');
|
|
3
|
+
export interface LoadConfigResult {
|
|
4
|
+
config: Config | undefined;
|
|
5
|
+
errors: esbuild.Message[];
|
|
6
|
+
warnings: esbuild.Message[];
|
|
7
|
+
}
|
|
8
|
+
export declare function findConfigFile(dir: string): string | undefined;
|
|
9
|
+
export declare function watchConfig(tsConfigPath: string, onBuild: (result: LoadConfigResult) => void): Promise<esbuild.BuildContext<{
|
|
10
|
+
entryPoints: string[];
|
|
11
|
+
bundle: true;
|
|
12
|
+
outfile: string;
|
|
13
|
+
format: "cjs";
|
|
14
|
+
platform: "node";
|
|
15
|
+
plugins: {
|
|
16
|
+
name: string;
|
|
17
|
+
setup(build: esbuild.PluginBuild): void;
|
|
18
|
+
}[];
|
|
19
|
+
}>>;
|
|
20
|
+
//# sourceMappingURL=loadConfig.d.ts.map
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.watchConfig = exports.findConfigFile = void 0;
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const esbuild = require("/Users/johnsonchu/Desktop/GitHub/tsslint/node_modules/.pnpm/esbuild@0.19.9/node_modules/esbuild/lib/main.js");
|
|
6
|
+
function findConfigFile(dir) {
|
|
7
|
+
const dirs = [dir];
|
|
8
|
+
let upDir;
|
|
9
|
+
while ((upDir = path.resolve(dir, '..')) !== dirs[dirs.length - 1]) {
|
|
10
|
+
dirs.push(upDir);
|
|
11
|
+
dir = upDir;
|
|
12
|
+
}
|
|
13
|
+
for (const dir of dirs) {
|
|
14
|
+
try {
|
|
15
|
+
return require.resolve('./tsslint.config.ts', { paths: [dir] });
|
|
16
|
+
}
|
|
17
|
+
catch { }
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.findConfigFile = findConfigFile;
|
|
21
|
+
async function watchConfig(tsConfigPath, onBuild) {
|
|
22
|
+
const jsConfigPath = tsConfigPath.slice(0, -'.ts'.length) + '.cjs';
|
|
23
|
+
const ctx = await esbuild.context({
|
|
24
|
+
entryPoints: [tsConfigPath],
|
|
25
|
+
bundle: true,
|
|
26
|
+
outfile: jsConfigPath,
|
|
27
|
+
format: 'cjs',
|
|
28
|
+
platform: 'node',
|
|
29
|
+
plugins: [{
|
|
30
|
+
name: 'tsslint',
|
|
31
|
+
setup(build) {
|
|
32
|
+
build.onEnd(result => {
|
|
33
|
+
let config;
|
|
34
|
+
if (!result.errors.length) {
|
|
35
|
+
delete require.cache[jsConfigPath];
|
|
36
|
+
try {
|
|
37
|
+
config = require(jsConfigPath).default;
|
|
38
|
+
}
|
|
39
|
+
catch (e) {
|
|
40
|
+
result.errors.push({ text: String(e) });
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
onBuild({
|
|
44
|
+
config: config,
|
|
45
|
+
errors: result.errors,
|
|
46
|
+
warnings: result.warnings,
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
}],
|
|
51
|
+
});
|
|
52
|
+
await ctx.watch();
|
|
53
|
+
return ctx;
|
|
54
|
+
}
|
|
55
|
+
exports.watchConfig = watchConfig;
|
|
56
|
+
//# sourceMappingURL=loadConfig.js.map
|
package/lib/tslint.d.ts
ADDED
package/lib/tslint.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseTSLintRule = exports.parseTSLintRules = void 0;
|
|
4
|
+
function parseTSLintRules(rules) {
|
|
5
|
+
const result = {};
|
|
6
|
+
for (const rule of rules) {
|
|
7
|
+
const { ruleName } = rule.getOptions();
|
|
8
|
+
result[ruleName] = parseTSLintRule(rule);
|
|
9
|
+
}
|
|
10
|
+
return result;
|
|
11
|
+
}
|
|
12
|
+
exports.parseTSLintRules = parseTSLintRules;
|
|
13
|
+
function parseTSLintRule(rule) {
|
|
14
|
+
return ({ sourceFile, reportError, reportWarning }) => {
|
|
15
|
+
const { ruleSeverity } = rule.getOptions();
|
|
16
|
+
if (ruleSeverity === 'off') {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const failures = rule.apply(sourceFile);
|
|
20
|
+
for (const failure of failures) {
|
|
21
|
+
failure.setRuleSeverity(ruleSeverity);
|
|
22
|
+
const report = failure.getRuleSeverity() === 'error' ? reportError : reportWarning;
|
|
23
|
+
for (let i = 0; i < failures.length; i++) {
|
|
24
|
+
const failure = failures[i];
|
|
25
|
+
const reporter = report(failure.getFailure(), failure.getStartPosition().getPosition(), failure.getEndPosition().getPosition());
|
|
26
|
+
if (failure.hasFix()) {
|
|
27
|
+
const fix = failure.getFix();
|
|
28
|
+
const replaces = Array.isArray(fix) ? fix : [fix];
|
|
29
|
+
for (const replace of replaces) {
|
|
30
|
+
if (replace) {
|
|
31
|
+
reporter.withFix('Replace with ' + replace.text, () => [{
|
|
32
|
+
fileName: sourceFile.fileName,
|
|
33
|
+
textChanges: [{
|
|
34
|
+
newText: replace.text,
|
|
35
|
+
span: {
|
|
36
|
+
start: replace.start,
|
|
37
|
+
length: replace.length,
|
|
38
|
+
},
|
|
39
|
+
}],
|
|
40
|
+
}]);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
exports.parseTSLintRule = parseTSLintRule;
|
|
49
|
+
//# sourceMappingURL=tslint.js.map
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { FileTextChanges, LanguageService, LanguageServiceHost, SourceFile, Diagnostic, ApplicableRefactorInfo, TextRange } from 'typescript/lib/tsserverlibrary';
|
|
2
|
+
import type * as esbuild from 'esbuild';
|
|
3
|
+
export interface ProjectContext {
|
|
4
|
+
configFile: string;
|
|
5
|
+
typescript: typeof import('typescript/lib/tsserverlibrary.js');
|
|
6
|
+
languageServiceHost: LanguageServiceHost;
|
|
7
|
+
languageService: LanguageService;
|
|
8
|
+
tsconfig?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface Config {
|
|
11
|
+
rules?: Rules;
|
|
12
|
+
plugins?: Plugin[];
|
|
13
|
+
}
|
|
14
|
+
export interface Plugin {
|
|
15
|
+
(projectContext: ProjectContext, configBuildResult: esbuild.BuildResult): PluginInstance | Promise<PluginInstance>;
|
|
16
|
+
}
|
|
17
|
+
export interface PluginInstance {
|
|
18
|
+
lint?(sourceFile: SourceFile, rules: Rules): Diagnostic[];
|
|
19
|
+
getFixes?(sourceFile: SourceFile, positionOrRange: number | TextRange): ApplicableRefactorInfo[];
|
|
20
|
+
fix?(sourceFile: SourceFile, refactorName: string, actionName: string): FileTextChanges[] | undefined;
|
|
21
|
+
resolveRules?(rules: Rules): Rules;
|
|
22
|
+
resolveResult?(results: Diagnostic[]): Diagnostic[];
|
|
23
|
+
}
|
|
24
|
+
export interface Rules {
|
|
25
|
+
[name: string]: Rule;
|
|
26
|
+
}
|
|
27
|
+
export interface Rule {
|
|
28
|
+
(context: RuleContext): void;
|
|
29
|
+
}
|
|
30
|
+
export interface RuleContext {
|
|
31
|
+
typescript: typeof import('typescript/lib/tsserverlibrary.js');
|
|
32
|
+
languageServiceHost: LanguageServiceHost;
|
|
33
|
+
languageService: LanguageService;
|
|
34
|
+
sourceFile: SourceFile;
|
|
35
|
+
reportError(message: string, start: number, end: number): Reporter;
|
|
36
|
+
reportWarning(message: string, start: number, end: number): Reporter;
|
|
37
|
+
reportSuggestion(message: string, start: number, end: number): Reporter;
|
|
38
|
+
}
|
|
39
|
+
export interface Reporter {
|
|
40
|
+
withDeprecated(): Reporter;
|
|
41
|
+
withUnnecessary(): Reporter;
|
|
42
|
+
withFix(title: string, getChanges: () => FileTextChanges[]): Reporter;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=types.d.ts.map
|
package/lib/types.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tsslint/config",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"files": [
|
|
6
|
+
"**/*.js",
|
|
7
|
+
"**/*.d.ts"
|
|
8
|
+
],
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/johnsoncodehk/tsslint.git",
|
|
12
|
+
"directory": "packages/config"
|
|
13
|
+
},
|
|
14
|
+
"peerDependencies": {
|
|
15
|
+
"tslint": "*"
|
|
16
|
+
},
|
|
17
|
+
"peerDependenciesMeta": {
|
|
18
|
+
"tslint": {
|
|
19
|
+
"optional": true
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|