diff --git a/package.json b/package.json index 02485f9e4ab2..a8bc7d5db587 100644 --- a/package.json +++ b/package.json @@ -29,8 +29,7 @@ "build-tsc": "tsc -p tsconfig.json", "debug:test": "node --inspect-brk ./bin/devkit-admin test", "debug:test-large": "node --inspect-brk ./bin/devkit-admin test --large --spec-reporter", - "fix": "node ./bin/devkit-admin lint --fix", - "lint": "node ./bin/devkit-admin lint", + "lint": "tslint --project tsconfig.json", "templates": "node ./bin/devkit-admin templates", "validate": "node ./bin/devkit-admin validate", "validate-commits": "./bin/devkit-admin validate-commits", diff --git a/scripts/README.md b/scripts/README.md index a5dc3b45bdc3..f970712d4aa2 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -42,14 +42,6 @@ Flags: * `--githubTokenFile=`. Reads the githubToken from a file instead of the command line (for CI). * `--stdout`. Skip the whole release note process and output the markdown to stdout instead. -## lint - -Runs tslint on the whole repo. - -Flags: - -* `--fix`. Also applies fixes. - ## packages Outputs a JSON containing all informations from the package script (main files, repo names, versions, deps, etc). diff --git a/scripts/lint.ts b/scripts/lint.ts deleted file mode 100644 index 6d15c10d1d8a..000000000000 --- a/scripts/lint.ts +++ /dev/null @@ -1,95 +0,0 @@ -/** - * @license - * Copyright Google Inc. All Rights Reserved. - * - * Use of this source code is governed by an MIT-style license that can be - * found in the LICENSE file at https://angular.io/license - */ -// tslint:disable:no-implicit-dependencies -// tslint:disable:no-console -import { logging } from '@angular-devkit/core'; -import { ParsedArgs } from 'minimist'; -import * as path from 'path'; -import { Configuration, ILinterOptions, Linter, findFormatter } from 'tslint'; -import * as ts from 'typescript'; - -function _buildRules(logger: logging.Logger) { - const tsConfigPath = path.join(__dirname, '../etc/rules/tsconfig.json'); - const configFile = ts.readConfigFile(tsConfigPath, ts.sys.readFile); - - const parsedTsConfig = ts.parseJsonConfigFileContent( - configFile.config, - ts.sys, - path.dirname(tsConfigPath), - ); - const lintRulesProgram = ts.createProgram(parsedTsConfig.fileNames, parsedTsConfig.options); - const result = lintRulesProgram.emit(); - - if (result.emitSkipped) { - const host: ts.FormatDiagnosticsHost = { - getCurrentDirectory: () => ts.sys.getCurrentDirectory(), - getNewLine: () => ts.sys.newLine, - getCanonicalFileName: (fileName: string) => fileName, - }; - logger.fatal(ts.formatDiagnostics(result.diagnostics, host)); - process.exit(100); - } -} - -export default async function(options: ParsedArgs, logger: logging.Logger) { - _buildRules(logger); - - const lintOptions: ILinterOptions = { - fix: options.fix, - }; - - const program = Linter.createProgram(path.join(__dirname, '../tsconfig.json')); - const linter = new Linter(lintOptions, program); - const tsLintPath = path.join(__dirname, '../tslint.json'); - const tsLintConfig = Configuration.loadConfigurationFromPath(tsLintPath); - - // Console is used directly by tslint, and when finding a rule that doesn't exist it's considered - // a warning by TSLint but _only_ shown on the console and impossible to see through the API. - // In order to see any warnings that happen from TSLint itself, we hook into console.warn() and - // record any calls. - const oldWarn = console.warn; - let warnings = false; - console.warn = (...args) => { - warnings = true; - oldWarn(...args); - }; - - program.getRootFileNames().forEach(fileName => { - linter.lint(fileName, ts.sys.readFile(fileName) || '', tsLintConfig); - }); - - console.warn = oldWarn; - - const result = linter.getResult(); - const Formatter = findFormatter('codeFrame'); - if (!Formatter) { - throw new Error('Cannot find lint formatter.'); - } - const formatter = new Formatter(); - - if (result.errorCount > 0) { - logger.error(formatter.format(result.failures)); - logger.info(`Errors: ${result.errorCount}`); - if (result.warningCount > 0) { - logger.info(`Warnings: ${result.warningCount}`); - } - - return 2; - } else if (result.warningCount > 0) { - logger.warn(formatter.format(result.failures)); - logger.info(`Warnings: ${result.warningCount}`); - - return 1; - } else if (warnings) { - logger.warn('TSLint found warnings, but code is okay. See above.'); - - return 1; - } - - return 0; -}