Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
linter.lint(
// append .ts so that tslint apply TS rules
filePath,
'',
// use Vue config to ignore blank lines
isVue ? vueConfig : config
);
restoreWriteFile();
};
const files = args._ && args._.length ? args._ : ['src/**/*.ts', 'src/**/*.vue', 'src/**/*.tsx', 'tests/**/*.ts', 'tests/**/*.tsx'];
// respect linterOptions.exclude from tslint.json
if (config.linterOptions && config.linterOptions.exclude) {
// use the raw tslint.json data because config contains absolute paths
const rawTslintConfig = tslint.Configuration.readConfigurationFile(tslintConfigPath);
const excludedGlobs = rawTslintConfig.linterOptions.exclude;
excludedGlobs.forEach((g) => files.push('!' + g));
}
return globby(files, { cwd }).then((files) => {
files.forEach(lint);
if (silent) return;
const result = linter.getResult();
if (result.output.trim()) {
process.stdout.write(result.output);
} else if (result.fixes.length) {
// some formatters do not report fixes.
const f = new tslint.Formatters.ProseFormatter();
process.stdout.write(f.format(result.failures, result.fixes));
} else if (!result.failures.length) {
console.log(`No lint errors found.\n`);
gulp.task("lint:tests", (done) => {
var program = tslint.Linter.createProgram("./test/tsconfig.json");
// we need to load and override the configuration
let config = tslint.Configuration.loadConfigurationFromPath("./tslint.json");
config.rules.set("no-unused-expression", { ruleSeverity: "off" });
pump([
gulp.src([
"./packages/**/*.test.ts",
"!**/node_modules/**",
"!**/*.d.ts"
]),
gulpTslint({
configuration: config,
formatter: "prose",
program: program,
}),
gulpTslint.report({ emitError: false }),
], (err) => {
public find(fileName: string) {
fileName = path.dirname(fileName);
let result = this.cache.get(fileName);
if (result === undefined && !this.cache.has(fileName)) {
result = TSLint.Configuration.findConfigurationPath(null, fileName); // tslint:disable-line:no-null-keyword
const {root} = path.parse(fileName);
// prevent infinite loop when result is on different drive
const configDirname = result === undefined || root !== path.parse(result).root ? root : path.dirname(result);
this.cache.set(fileName, result);
while (fileName !== configDirname) {
this.cache.set(fileName, result);
fileName = path.dirname(fileName);
}
}
return result;
}
var Filter = require('broccoli-persistent-filter');
var chalk = require('chalk');
var existsSync = require('exists-sync');
var path = require('path');
var Linter = require('tslint').Linter;
var Configuration = require('tslint').Configuration;
var fs = require('fs');
var testGenerators = require('aot-test-generators');
function TSLint(inputNode, options) {
if (!(this instanceof TSLint)) {
return new TSLint(inputNode, options);
}
options = options || {};
this.options = {
outputFile: options.outputFile,
failBuild: options.failBuild || false,
disableTestGenerator: options.disableTestGenerator || false,
testGenerator: options.testGenerator || null,
logError: options.logError
};
exports.runTSLint = function(directory, files, useServices) {
const program = useServices
? tslint.Linter.createProgram(`${directory}tsconfig.json`)
: undefined;
const linter = new tslint.Linter(
{
fix: false,
formatter: 'json'
},
program
);
const tslintConfig = tslint.Configuration.loadConfigurationFromPath(
`./${directory}tslint.json`
);
for (const file of files) {
linter.lint(
file,
fs.readFileSync(path.join(__dirname, file), 'utf8'),
tslintConfig
);
}
const result = linter.getResult();
if (result.errorCount === 0) {
throw new Error('something went wrong');
}
return result.failures[0].failure;
};
constructor(project: Project, config: TargetConfig) {
this.project = project;
this.id = config.id;
this.uid = this.project.id + ":" + this.id;
this.path = config.path !== void 0 ? config.path : this.id;
this.baseDir = path.resolve(this.project.baseDir, this.path);
this.deps = [];
this.preamble = config.preamble;
this.compilerOptions = config.compilerOptions || this.project.compilerOptions;
this.lintConfig = tslint.Configuration.findConfiguration(null, this.baseDir).results!;
this.selected = false;
this.watching = false;
this.failed = false;
this.retest = false;
this.redoc = false;
this.compileStart = 0;
this.bundleTimer = 0;
this.bundle = this.bundle.bind(this);
this.onBundleWarning = this.onBundleWarning.bind(this);
this.onBundleError = this.onBundleError.bind(this);
}
const isVue = isVueFile(file)
patchWriteFile()
linter.lint(
filePath,
'',
isVue ? vueConfig : config
)
restoreWriteFile()
}
const files = args._ && args._.length
? args._
: [cwd + '/src/**/*.ts', cwd + '/src/**/*.vue', cwd + '/src/**/*.tsx']
if (config.linterOptions && config.linterOptions.exclude) {
const rawTslintConfig = tslint.Configuration.readConfigurationFile(tslintConfigPath)
const excludedGlobs = rawTslintConfig.linterOptions.exclude
excludedGlobs.forEach((g) => files.push('!' + g))
}
return globby(files, { cwd }).then(files => {
files.forEach(lint)
if (silent) return
const result = linter.getResult()
if (result.output.trim()) {
process.stdout.write(result.output)
} else if (result.fixes.length) {
const f = new tslint.Formatters.ProseFormatter()
process.stdout.write(f.format(result.failures, result.fixes))
} else if (!result.failures.length) {
done('tslint 没有发现错误.\n')
}
function getLinterOptions(configFile) {
const { results } = TSLint.Configuration.findConfiguration(
"tslint.json",
configFile
);
return results;
}
function getLinter(options) {
configuration = configuration ? configuration : tslint.Configuration.findConfiguration(null, '.');
const program = tslint.Linter.createProgram('./tsconfig.json');
const linter = new tslint.Linter({ formatter: 'json' }, program);
return { linter, configuration };
}
let compilationInProgress = false;
rulesDirectory: ((): string[] => {
const msCustomRulesMain: string = require.resolve('tslint-microsoft-contrib');
const msCustomRulesDirectory: string = path.dirname(msCustomRulesMain);
return TSLint.Configuration.getRulesDirectories([msCustomRulesDirectory], __dirname);
})(),
sourceMatch: [