Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const linter = new Linter({ fix, formatter: 'codeFrame' });
linter.lint(file, source, configuration);
const result = linter.getResult();
if (result.errorCount || result.warningCount) {
options.logger.log(result.output);
return false;
}
return true;
});
return rcs.every(rc => rc); // if all files succeeded.
} else {
// Lint the set of files specified by the typescript program config.
const program = createProgram(options);
files = Linter.getFileNames(program);
const configPath = fs.existsSync(
path.join(options.targetRootDir, 'tslint.json')
)
? path.resolve(options.targetRootDir, 'tslint.json')
: path.resolve(options.gtsRootDir, 'tslint.json');
const configuration = Configuration.loadConfigurationFromPath(configPath);
for (const file of files) {
const sourceFile = program.getSourceFile(file);
if (sourceFile) {
const fileContents = sourceFile.getFullText();
const linter = new Linter({ fix, formatter: 'codeFrame' }, program);
linter.lint(file, fileContents, configuration);
const result = linter.getResult();
function lint(program) {
let linter = new Linter(
{
formatter: "codeFrame"
},
program
);
const files = Linter.getFileNames(program);
files.forEach(file => {
const fileContents = program.getSourceFile(file).getFullText();
const configuration = Configuration.findConfiguration("tslint.json", file)
.results;
linter.lint(file, fileContents, configuration);
});
const results = linter.getResult();
if (results.errorCount > 0 || results.warningCount > 0) {
console.log(results.output);
process.exit(1);
}
}
const lint = () => async function lint() {
const configurationFilename = './tslint.json';
const options = {
fix: false,
formatter: 'stylish',
};
const program = Linter.createProgram('tsconfig.json');
const linter = new Linter(options, program);
const files = Linter.getFileNames(program);
files.forEach((fileName) => {
const fileContents = program.getSourceFile(fileName).getFullText();
const configuration = Configuration.findConfiguration(configurationFilename, fileName).results;
linter.lint(fileName, fileContents, configuration);
});
const result = linter.getResult();
console.error(result.output);
};
private lintFilesAsync() {
const program = Linter.createProgram(this.tsconfig);
const linter = new Linter({ fix: this.autofix, formatter: Formatter }, program);
const files = Linter.getFileNames(program);
const configuration = Configuration.findConfiguration(this.tslintCfg).results;
const lintInEventLoop = (remainingFiles: string[]) => {
const file = remainingFiles.shift()!;
const fileContents = program.getSourceFile(file)!.getFullText();
linter.lint(file, fileContents, configuration);
if (remainingFiles.length && !this.terminated) {
setImmediate(lintInEventLoop, remainingFiles);
} else {
this.running = false;
if (this.terminated) {
debugLog("Tslint: Aborted", this.tsconfig);
} else {
this.lastResult = linter.getResult().output;
const result = (() => {
if (projectFileName && !pattern) {
const projectDir = path.dirname(path.resolve(projectFileName));
const program = Linter.createProgram(projectFileName, projectDir);
const linter = new Linter(options, program);
const files = Linter.getFileNames(program);
for (const file of files) {
const sourceFile = program.getSourceFile(file);
if (sourceFile) {
const fileContents = sourceFile.getFullText();
const configuration = Configuration.findConfiguration(configFileName, file).results;
linter.lint(file, fileContents, configuration);
}
}
return linter.getResult();
} else {
const linter = new Linter(options);
const files = glob.sync(pattern!);
for (const file of files) {
const fileContents = fs.readFileSync(file, { encoding: "utf8" });
export function getFileNames(context: BuildContext, tsConfig: string): string[] {
const program = createProgram(context, tsConfig);
return Linter.getFileNames(program);
}