eslint-plugin-tsc
Advanced tools
Comparing version
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const program_1 = require("./program"); | ||
const flatMap = require("1-liners/flatMap"); | ||
function create(context) { | ||
const { compilerOptions, configFile } = context.options[0] || { compilerOptions: {}, configFile: null }; | ||
function config(context) { | ||
const { compilerOptions, configFile } = context.options[0] || { compilerOptions: {}, configFile: undefined }; | ||
const program = program_1.getProgram({ configFile, compilerOptions }); | ||
// TODO: Handle ts.getPreEmitDiagnostics(program) result | ||
const fileName = context.getFilename(); | ||
const sourceFile = program.getSourceFile(fileName); | ||
const diagnostics = flatMap(item => item, [ | ||
program.getSemanticDiagnostics(sourceFile), | ||
program.getSyntacticDiagnostics(sourceFile), | ||
program.getDeclarationDiagnostics(sourceFile), | ||
]); | ||
const diagnostics = [ | ||
...program.getSemanticDiagnostics(sourceFile), | ||
...program.getSyntacticDiagnostics(sourceFile), | ||
]; | ||
diagnostics.forEach(diagnostic => { | ||
@@ -28,27 +25,3 @@ if (diagnostic.file) { | ||
} | ||
exports.create = create; | ||
exports.config = { | ||
create, | ||
meta: { | ||
docs: { | ||
description: 'Wraps a TypeScript compiler checks', | ||
category: 'TypeScript', | ||
}, | ||
schema: [ | ||
{ | ||
type: 'object', | ||
additionalProperties: false, | ||
properties: { | ||
compilerOptions: { | ||
type: 'object', | ||
additionalProperties: true, | ||
}, | ||
configFile: { | ||
type: 'string' | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
}; | ||
exports.config = config; | ||
//# sourceMappingURL=config.js.map |
@@ -6,8 +6,2 @@ "use strict"; | ||
const path = require("path"); | ||
const diagnosticsCompilerOptions = { | ||
noEmit: true, | ||
sourceMap: false, | ||
inlineSources: false, | ||
inlineSourceMap: false, | ||
}; | ||
exports.getProgram = (() => { | ||
@@ -26,3 +20,3 @@ let program; | ||
throw new Error(ts.formatDiagnostics([config.error], { | ||
getCanonicalFileName: fn => fn, | ||
getCanonicalFileName: file => file, | ||
getCurrentDirectory: process.cwd, | ||
@@ -32,2 +26,6 @@ getNewLine: () => '\n', | ||
} | ||
if (config.config) { | ||
delete config.config.include; | ||
delete config.config.exclude; | ||
} | ||
const parseConfigHost = { | ||
@@ -45,3 +43,3 @@ fileExists: fs.existsSync, | ||
} | ||
const resultCompilerOptions = Object.assign({}, compilerOptions, diagnosticsCompilerOptions); | ||
const resultCompilerOptions = Object.assign({}, compilerOptions, { noEmit: true, sourceMap: false, inlineSources: false, inlineSourceMap: false }); | ||
const parsed = ts.parseJsonConfigFileContent(config.config, parseConfigHost, path.resolve(projectDirectory), resultCompilerOptions); | ||
@@ -48,0 +46,0 @@ if (parsed.errors) { |
{ | ||
"name": "eslint-plugin-tsc", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "description": "eslint-plugin-tsc", |
@@ -5,18 +5,14 @@ import * as ts from 'typescript'; | ||
import noop = require('1-liners/noop'); | ||
import flatMap = require('1-liners/flatMap'); | ||
export function create(context: Rule.RuleContext) { | ||
export function config(context: Rule.RuleContext) { | ||
const { compilerOptions, configFile } = context.options[0] || { compilerOptions: {}, configFile: null }; | ||
const { compilerOptions, configFile } = context.options[0] || { compilerOptions: {}, configFile: undefined }; | ||
const program: ts.Program = getProgram({ configFile, compilerOptions }); | ||
// TODO: Handle ts.getPreEmitDiagnostics(program) result | ||
const fileName = context.getFilename(); | ||
const sourceFile = program.getSourceFile(fileName); | ||
const diagnostics: ReadonlyArray<ts.Diagnostic> = flatMap(item => item, [ | ||
program.getSemanticDiagnostics(sourceFile), | ||
program.getSyntacticDiagnostics(sourceFile), | ||
program.getDeclarationDiagnostics(sourceFile), | ||
]); | ||
const diagnostics: ReadonlyArray<ts.Diagnostic> = [ | ||
...program.getSemanticDiagnostics(sourceFile), | ||
...program.getSyntacticDiagnostics(sourceFile), | ||
]; | ||
@@ -36,26 +32,1 @@ diagnostics.forEach(diagnostic => { | ||
} | ||
export const config = { | ||
create, | ||
meta: { | ||
docs: { | ||
description: 'Wraps a TypeScript compiler checks', | ||
category: 'TypeScript', | ||
}, | ||
schema: [ | ||
{ | ||
type: 'object', | ||
additionalProperties: false, | ||
properties: { | ||
compilerOptions: { | ||
type: 'object', | ||
additionalProperties: true, | ||
}, | ||
configFile: { | ||
type: 'string' | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
}; |
import { config } from './config'; | ||
import { Rule } from 'eslint'; | ||
export const rules = { | ||
type RuleDict = { [id: string]: Rule.RuleModule | ((context: Rule.RuleContext) => Rule.RuleListener) }; | ||
export const rules: RuleDict = { | ||
config, | ||
}; |
@@ -11,9 +11,2 @@ import * as ts from 'typescript'; | ||
const diagnosticsCompilerOptions: ts.CompilerOptions = { | ||
noEmit: true, | ||
sourceMap: false, | ||
inlineSources: false, | ||
inlineSourceMap: false, | ||
}; | ||
export const getProgram = (() => { | ||
@@ -33,3 +26,3 @@ let program: ts.Program; | ||
throw new Error(ts.formatDiagnostics([config.error], { | ||
getCanonicalFileName: fn => fn, | ||
getCanonicalFileName: file => file, | ||
getCurrentDirectory: process.cwd, | ||
@@ -39,2 +32,6 @@ getNewLine: () => '\n', | ||
} | ||
if (config.config) { | ||
delete config.config.include; | ||
delete config.config.exclude; | ||
} | ||
const parseConfigHost: ts.ParseConfigHost = { | ||
@@ -52,3 +49,9 @@ fileExists: fs.existsSync, | ||
} | ||
const resultCompilerOptions = { ...compilerOptions, ...diagnosticsCompilerOptions }; | ||
const resultCompilerOptions: ts.CompilerOptions = { | ||
...compilerOptions, | ||
noEmit: true, | ||
sourceMap: false, | ||
inlineSources: false, | ||
inlineSourceMap: false, | ||
}; | ||
const parsed = ts.parseJsonConfigFileContent(config.config, parseConfigHost, path.resolve(projectDirectory), resultCompilerOptions); | ||
@@ -55,0 +58,0 @@ if (parsed.errors) { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
16701
-9.36%214
-18.94%