build: no longer run tslint from within gulp task (#35800)

Switches our tslint setup to the standard `tslint.json` linter excludes.
The set of files that need to be linted is specified through a Yarn script.

For IDEs, open files are linted with the closest tslint configuration, if the
tslint IDE extension is set up, and the source file is not excluded.

We cannot use the language service plugin for tslint as we have multiple nested
tsconfig files, and we don't want to add the plugin to each tsconfig. We
could reduce that bloat by just extending from a top-level tsconfig that
defines the language service plugin, but unfortunately the tslint plugin does
not allow the use of tslint configs which are not part of the tsconfig project.

This is problematic since the tslint configuration is at the project root, and we
don't want to copy tslint configurations next to each tsconfig file.

Additionally, linting of `d.ts` files has been re-enabled. This has been
disabled in the past and a TODO has been left. This commit fixes the
lint issues and re-enables linting.

PR Close #35800
This commit is contained in:
Paul Gschwendtner 2020-03-02 18:35:30 +01:00 committed by atscott
parent 5349e46b46
commit 5615928df9
28 changed files with 171 additions and 138 deletions

View File

@ -274,7 +274,7 @@ jobs:
- run: 'yarn bazel:lint ||
(echo -e "\n.bzl files have lint errors. Please run ''yarn bazel:lint-fix''"; exit 1)'
- run: yarn gulp lint
- run: yarn lint
- run: node tools/pullapprove/verify.js
test:

View File

@ -129,7 +129,7 @@ where `$ANGULAR_PATH` is an environment variable of the absolute path of your An
You can check that your code is properly formatted and adheres to coding style by running:
``` shell
$ yarn gulp lint
$ yarn lint
```
## Publishing Snapshot Builds

View File

@ -45,11 +45,9 @@ gulp.task('format:changed', ['format:untracked', 'format:diff']);
// Alias for `format:changed` that formerly formatted all files.
gulp.task('format', ['format:changed']);
gulp.task('lint', ['format:enforce', 'validate-commit-messages', 'tslint']);
gulp.task('tslint', ['tools:build'], loadTask('lint'));
gulp.task('lint', ['format:enforce', 'validate-commit-messages']);
gulp.task('validate-commit-messages', loadTask('validate-commit-message'));
gulp.task('source-map-test', loadTask('source-map-test'));
gulp.task('tools:build', loadTask('tools-build'));
gulp.task('changelog', loadTask('changelog'));
gulp.task('changelog:zonejs', loadTask('changelog-zonejs'));
gulp.task('check-env', () => {/* this is a noop because the env test ran already above */});

8
modules/system.d.ts vendored
View File

@ -1,4 +1,10 @@
/**
* Dummy typings for systemjs.
* @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
*/
/** Dummy typings for systemjs. */
declare var System: any;

View File

@ -30,7 +30,9 @@
"bazel": "bazel",
"//circleci-win-comment": "See the test-win circleci job for why these are needed. If they are not needed anymore, remove them.",
"circleci-win-ve": "bazel test --build_tag_filters=-ivy-only --test_tag_filters=-ivy-only,-browser:chromium-local //packages/compiler-cli/... //tools/ts-api-guardian/...",
"circleci-win-ivy": "bazel test --config=ivy --build_tag_filters=-no-ivy-aot,-fixme-ivy-aot --test_tag_filters=-no-ivy-aot,-fixme-ivy-aot,-browser:chromium-local //packages/compiler-cli/... //tools/ts-api-guardian/..."
"circleci-win-ivy": "bazel test --config=ivy --build_tag_filters=-no-ivy-aot,-fixme-ivy-aot --test_tag_filters=-no-ivy-aot,-fixme-ivy-aot,-browser:chromium-local //packages/compiler-cli/... //tools/ts-api-guardian/...",
"lint": "yarn -s tslint && yarn gulp lint",
"tslint": "tsc -p tools/tsconfig.json && tslint -c tslint.json \"+(packages|modules|scripts|tools)/**/*.+(js|ts)\""
},
"// 1": "dependencies are used locally and by bazel",
"dependencies": {

View File

@ -1,9 +1,10 @@
// THIS FILE IS AUTOMATICALLY GENERATED. TO UPDATE THIS FILE YOU NEED TO CHANGE THE
// CORRESPONDING JSON SCHEMA FILE, THEN RUN devkit-admin build (or bazel build ...).
// tslint:disable:no-global-tslint-disable
// tslint:disable
/**
* @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
*/
/**
* Options for Bazel Builder

View File

@ -1,9 +1,10 @@
// THIS FILE IS AUTOMATICALLY GENERATED. TO UPDATE THIS FILE YOU NEED TO CHANGE THE
// CORRESPONDING JSON SCHEMA FILE, THEN RUN devkit-admin build (or bazel build ...).
// tslint:disable:no-global-tslint-disable
// tslint:disable
/**
* @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
*/
export interface Schema {
/**

View File

@ -1,8 +1,11 @@
/**
* @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
*/
// THIS FILE IS AUTOMATICALLY GENERATED. TO UPDATE THIS FILE YOU NEED TO CHANGE THE
// CORRESPONDING JSON SCHEMA FILE, THEN RUN devkit-admin build (or bazel build ...).
// tslint:disable
export interface Schema {
/**
* Initial git repository commit information.

View File

@ -91,7 +91,7 @@ export function createBenchmark(benchmarkName: string): Benchmark {
return (previous.bestTime < current.bestTime) ? previous : current;
});
const unitOffset = findUnit(fastest.bestTime);
(fn || console.log)(`\nBenchmark: ${benchmarkName}\n${profiles.map((profile: Profile) => {
(fn || console.info)(`\nBenchmark: ${benchmarkName}\n${profiles.map((profile: Profile) => {
const time = formatTime(profile.bestTime, unitOffset);
const percent = formatPercent(1 - profile.bestTime / fastest.bestTime);
return ` ${profile.profileName}: ${time}(${percent}) `;

View File

@ -1,3 +1,4 @@
// tslint:disable:file-header
/**
* Copyright (c) 2016, Tiernan Cridland
*

View File

@ -1,4 +1,10 @@
/**
* Dummy typings for systemjs.
* @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
*/
/** Dummy typings for systemjs. */
declare var System: any;

View File

@ -37,12 +37,12 @@ var tunnel = new BrowserStackTunnel({
hosts: hosts
});
console.log('Starting tunnel on ports', PORTS.join(', '));
console.info('Starting tunnel on ports', PORTS.join(', '));
tunnel.start(function(error) {
if (error) {
console.error('Can not establish the tunnel', error);
} else {
console.log('Tunnel established.');
console.info('Tunnel established.');
fakeServers.forEach(function(server) {
server.close();
});

View File

@ -1,4 +1,11 @@
#!/usr/bin/env node
/**
* @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
*/
'use strict';
const {buildTargetPackages} = require('./package-builder');

View File

@ -1,4 +1,12 @@
#!/usr/bin/env node
/**
* @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
*/
'use strict';
const {chmod, cp, mkdir, rm} = require('shelljs');
@ -22,18 +30,18 @@ buildTargetPackages('dist/packages-dist', false, 'Production');
// copied into the `dist/packages-dist/` directory (despite its source's being inside
// `packages/`), because it is not published to npm under the `@angular` scope (as happens for
// the rest of the packages).
console.log('');
console.log('##############################');
console.log(`${scriptPath}:`);
console.log(' Building zone.js npm package');
console.log('##############################');
console.info('');
console.info('##############################');
console.info(`${scriptPath}:`);
console.info(' Building zone.js npm package');
console.info('##############################');
exec(`${bazelCmd} build //packages/zone.js:npm_package`);
// Copy artifacts to `dist/zone.js-dist/`, so they can be easier persisted on CI.
const buildOutputDir = `${bazelBin}/packages/zone.js/npm_package`;
const distTargetDir = `${baseDir}/dist/zone.js-dist/zone.js`;
console.log(`# Copy artifacts to ${distTargetDir}`);
console.info(`# Copy artifacts to ${distTargetDir}`);
mkdir('-p', distTargetDir);
rm('-rf', distTargetDir);
cp('-R', buildOutputDir, distTargetDir);

View File

@ -1,3 +1,11 @@
/**
* @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
*/
'use strict';
// Imports
@ -27,7 +35,7 @@ for (const compressionType in limitSizes) {
failed = true;
// An expected compression type/file combination is missing. Maybe the file was renamed or
// removed. Report it as an error, so the user updates the corresponding limit file.
console.log(
console.error(
`ERROR: Commit ${commit} ${compressionType} ${filename} measurement is missing. ` +
'Maybe the file was renamed or removed.');
} else {
@ -54,11 +62,11 @@ for (const compressionType in limitSizes) {
}
// Group failure messages separately from success messages so they are easier to find.
successMessages.concat(failureMessages).forEach(message => console.log(message));
successMessages.concat(failureMessages).forEach(message => console.error(message));
if (failed) {
console.log(`If this is a desired change, please update the size limits in file '${limitFile}'.`);
console.info(`If this is a desired change, please update the size limits in file '${limitFile}'.`);
process.exit(1);
} else {
console.log(`Payload size check passed. All diffs are less than 1% or 500 bytes.`);
console.info(`Payload size check passed. All diffs are less than 1% or 500 bytes.`);
}

View File

@ -1,4 +1,12 @@
/**
* @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
*/
/*
* This script updates a package.json file by replacing all dependencies and devDependencies
* such that all packages from the @angular scope point to the packages-dist directory.
*
@ -52,12 +60,12 @@ writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
// Log all packages that were updated
if (updated.length > 0) {
console.log(green(`Updated ${packageJsonPath} to packages in ${packagesDistRoot}:`));
console.log(` ${updated.join('\n ')}\n`);
console.info(green(`Updated ${packageJsonPath} to packages in ${packagesDistRoot}:`));
console.info(` ${updated.join('\n ')}\n`);
}
// Log the packages that were skipped, as they were not present in the packages-dist directory
if (skipped.length > 0) {
console.log(yellow(`Did not update packages that were not present in ${packagesDistRoot}:`));
console.log(` ${skipped.join('\n ')}\n`);
console.info(yellow(`Did not update packages that were not present in ${packagesDistRoot}:`));
console.info(` ${skipped.join('\n ')}\n`);
}

View File

@ -28,7 +28,7 @@ function httpGet(server, path, headers) {
})
.on('error', (e) => reject(e));
});
};
}
let warnNoToken = true;
@ -47,7 +47,7 @@ async function githubGet(path) {
}
return JSON.parse(await httpGet('api.github.com', '/repos/angular/angular/' + path, headers));
};
}
async function githubPrInfo(prNumber) {
const pr = (await githubGet('pulls/' + prNumber));
@ -62,7 +62,7 @@ async function githubPrInfo(prNumber) {
},
branch: branch
};
}; // trailing ; so that clang-format is not confused on async function
}
function gitHasLocalModifications() {
return execNoFatal('git diff-index --quiet HEAD --').code != 0;

View File

@ -1,5 +1,13 @@
#!/usr/bin/env node
/**
* @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
*/
var msg = '';
if (require.main === module) {
@ -14,7 +22,7 @@ if (require.main === module) {
process.stdin.on('end', () => {
var argv = process.argv.slice(2);
console.log(rewriteMsg(msg, argv[0]));
console.info(rewriteMsg(msg, argv[0]));
});
}

View File

@ -1,5 +1,13 @@
#!/usr/bin/env node
/**
* @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
*/
var json = '';
if (require.main === module) {
@ -16,8 +24,8 @@ if (require.main === module) {
var obj = JSON.parse(json);
var argv = process.argv.slice(2);
extractPaths(obj, argv).forEach(function(line) {
console.log(line);
})
console.info(line);
});
});
}

View File

@ -1,5 +1,13 @@
#!/usr/bin/env node
/**
* @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
*/
var assert = require("assert");
var extractPaths = require('./json_extract').extractPaths;

View File

@ -1,3 +1,11 @@
/**
* @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
*/
'use strict';
// Build the dist/packages-dist directory in the same fashion as the legacy
@ -51,11 +59,11 @@ module.exports = {
* @param {string} description Human-readable description of the build.
*/
function buildTargetPackages(destPath, enableIvy, description) {
console.log('##################################');
console.log(`${scriptPath}:`);
console.log(' Building @angular/* npm packages');
console.log(` Mode: ${description}`);
console.log('##################################');
console.info('##################################');
console.info(`${scriptPath}:`);
console.info(' Building @angular/* npm packages');
console.info(` Mode: ${description}`);
console.info('##################################');
// List of targets to build, e.g. core, common, compiler, etc. Note that we want to also remove
// all carriage return (`\r`) characters form the query output, because otherwise the carriage
@ -79,7 +87,7 @@ function buildTargetPackages(destPath, enableIvy, description) {
const destDir = `${absDestPath}/${pkg}`;
if (test('-d', srcDir)) {
console.log(`# Copy artifacts to ${destDir}`);
console.info(`# Copy artifacts to ${destDir}`);
rm('-rf', destDir);
cp('-R', srcDir, destDir);
chmod('-R', 'u+w', destDir);

View File

@ -1,6 +1,4 @@
#!/usr/bin/env node
'use strict';
/**
* @license
* Copyright Google Inc. All Rights Reserved.
@ -8,6 +6,7 @@
* 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
*/
'use strict';
// Use process.cwd() so that this script is portable and can be used in /aio
// where this will require /aio/node_modules/puppeteer
const puppeteerPkgPath = require.resolve('puppeteer/package.json', {paths: [process.cwd()]});

View File

@ -52,5 +52,5 @@ gulp.task('format:enforce', loadTask('format', 'enforce'));
E.g. Loading a task that has dependencies:
```js
gulp.task('lint', ['format:enforce', 'tools:build'], loadTask('lint'));
gulp.task('lint', ['format:enforce'], loadTask('lint'));
```

View File

@ -1,54 +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
*/
// Check the coding standards and programming errors
module.exports = (gulp) => () => {
const tslint = require('gulp-tslint');
// Built-in rules are at https://palantir.github.io/tslint/rules/
const path = require('path');
return gulp
.src([
// TODO(vicb): add .js files when supported
// see https://github.com/palantir/tslint/pull/1515
'./modules/**/*.ts',
'./modules/**/*.js',
'./packages/**/*.ts',
'./packages/**/*.js',
'./tools/**/*.ts',
'./tools/**/*.js',
'./*.ts',
// Ignore node_modules directories
'!**/node_modules/**',
// Ignore built files directories
'!**/built/**',
'!**/dist/**',
// Ignore special files
'!**/*.externs.js',
// Ignore generated files due to lack of copyright header
// TODO(alfaproject): make generated files lintable
'!**/*.d.ts',
'!**/*.ngfactory.ts',
// Ignore zone.js directory
// TODO(JiaLiPassion): add zone.js back later
'!packages/zone.js/**/*.js',
'!packages/zone.js/**/*.ts',
// Ignore test files
'!packages/localize/**/test_files/**',
])
.pipe(tslint({
configuration: path.resolve(__dirname, '../../tslint.json'),
formatter: 'prose',
}))
.pipe(tslint.report({emitError: true}));
};

View File

@ -1,23 +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
*/
function tsc(projectPath, done) {
const path = require('path');
const platformScriptPath = require('./platform-script-path');
const childProcess = require('child_process');
childProcess
.spawn(
path.join(__dirname, platformScriptPath('../../node_modules/.bin/tsc')),
['-p', path.join(__dirname, '../..', projectPath)], {stdio: 'inherit'})
.on('close', done);
}
module.exports = (gulp) => (done) => {
tsc('tools/', done);
};

View File

@ -23,7 +23,7 @@ try {
const {set, cd, sed, echo, ls, rm} = require('shelljs');
const {readFileSync} = require('fs');
const path = require('path');
const log = console.log;
const log = console.info;
// COMMENTED OUT BECAUSE WE CURRENTLY REQUIRE NO PATCHES
// UNCOMMENT TO REENABLE PATCHING AND LOG OUTPUT

8
tools/types.d.ts vendored
View File

@ -1,3 +1,11 @@
/**
* @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
*/
// This file contains all ambient imports needed to compile the tools source code
/// <reference types="jasmine" />

View File

@ -73,5 +73,27 @@
true,
"function"
]
},
"linterOptions": {
"exclude": [
"**/node_modules/**/*",
// Ignore AIO and integration tests.
"./aio/**/*",
"./integration/**/*",
// Ignore output directories
"./built/**/*",
"./dist/**/*",
"./bazel-out/**/*",
// Ignore special files
"**/*.externs.js",
// Ignore test files
"./packages/localize/**/test_files/**/*",
"./tools/ts-api-guardian/test/fixtures/**/*",
"./tools/public_api_guard/**/*.d.ts",
"./modules/benchmarks_external/**/*",
// Ignore zone.js directory
// TODO(JiaLiPassion): add zone.js back later
"./packages/zone.js/**/*"
]
}
}