Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
traceConfigurationFile(configuration.linterConfiguration)
}
// tslint writes warnings using console.warn, capture these warnings and send them to the client
let originalConsoleWarn = console.warn
let captureWarnings = (message?: any) => {
conn.sendNotification(StatusNotification.type, { state: Status.warn })
originalConsoleWarn(message)
}
console.warn = captureWarnings
try {
// protect against tslint crashes
let linter = getLinterFromLibrary(library)
if (isTsLintVersion4(library)) {
let program = settings.run == 'onSave' ? Linter.createProgram(settings.tsConfigFile) : undefined
let tslint = new linter(options, program)
trace(`Linting: start linting with tslint > version 4`)
tslint.lint(fsPath, contents, configuration.linterConfiguration)
result = tslint.getResult()
trace(`Linting: ended linting`)
}
// support for linting js files is only available in tslint > 4.0
else if (!isJsDocument(document)) {
(options as any).configuration = configuration.linterConfiguration
trace(`Linting: with tslint < version 4`)
let tslint = new (linter as any)(fsPath, contents, options)
result = tslint.lint()
trace(`Linting: ended linting`)
} else {
trace(`No linting: JS linting not supported in tslint < version 4`)
return diagnostics
* along with ng2-json-editor; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
* In applying this license, CERN does not
* waive the privileges and immunities granted to it by virtue of its status
* as an Intergovernmental Organization or submit itself to any jurisdiction.
*/
// modules
var gulp = require('gulp');
var sass = require('gulp-sass');
var extReplace = require('gulp-ext-replace');
var ngc = require('gulp-ngc');
var del = require('del');
var tsLint = require('gulp-tslint');
var Linter = require('tslint').Linter;
var tsLintProgram = Linter.createProgram('./src/tsconfig.json');
var inlineResources = require('inline-ng2-resources');
var KarmaServer = require('karma').Server;
var runSequence = require('run-sequence');
// run tslint
gulp.task('tslint', () => {
return gulp.src('./src/**/*.ts', { base: '.' })
.pipe(tsLint({
program: tsLintProgram,
formatter: 'prose'
}))
.pipe(tsLint.report({
summarizeFailureOutput: true
}))
});
export function createProgram(options: Options): ts.Program {
const tsconfigPath = path.join(options.targetRootDir, 'tsconfig.json');
return Linter.createProgram(tsconfigPath);
}
export function createProgram(context: BuildContext, tsConfig: string): Program {
return Linter.createProgram(tsConfig, context.rootDir);
}
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);
function lint(dir: string, configFileName?: string, fixtureFileName?: string): LintResult {
const fixturesDir = path.resolve("./fixtures");
const fixtureDir = `${fixturesDir}/${dir}`;
const fileName = `${fixtureDir}/${fixtureFileName || "fixture.ts"}`;
const content = fs.readFileSync(fileName, "utf8");
const program = Linter.createProgram(`${fixtureDir}/tsconfig.json`);
const linter = new Linter({ fix: false }, program);
const configuration = Configuration.findConfiguration(
configFileName ?
`${fixtureDir}/${configFileName}` :
`${fixturesDir}/tslint.json`,
fileName
).results;
linter.lint(fileName, content, configuration);
return linter.getResult();
}
});