Skip to content

Commit aadfcb5

Browse files
crisbetommalerba
authored andcommitted
build: no longer depend on gulp for lint tasks (#17516)
* Fixes the `prefer-literal` lint rule not actually running because it wasn't loaded in the tslint.json. * Converts the CODEOWNERS linting task into a regular Node script that doesn't depend on Gulp. * Turns the `stylelint` and `tslint` tasks into npm scripts. * Runs the new npm scripts directly rather than through Gulp on the CI.
1 parent 08d78f9 commit aadfcb5

File tree

7 files changed

+82
-98
lines changed

7 files changed

+82
-98
lines changed

.circleci/config.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ jobs:
252252
- run: ./scripts/circleci/run-saucelabs-tests.sh
253253

254254
# ----------------------------------
255-
# Lint job. Runs the gulp lint task.
255+
# Lint job.
256256
# ----------------------------------
257257
lint:
258258
<<: *job_defaults
@@ -271,7 +271,9 @@ jobs:
271271
yarn check-rollup-globals $(bazel info bazel-bin)/rollup_globals.json
272272
273273
- run: ./scripts/circleci/lint-bazel-files.sh
274-
- run: yarn gulp ci:lint
274+
- run: yarn ownerslint
275+
- run: yarn stylelint
276+
- run: yarn tslint
275277

276278
- *save_cache
277279

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@
3535
"format:bazel": "yarn -s bazel:buildifier --lint=fix --mode=fix",
3636
"format": "yarn -s format:ts && yarn -s format:bazel",
3737
"cherry-pick-patch": "ts-node --project tools/cherry-pick-patch/ tools/cherry-pick-patch/cherry-pick-patch.ts",
38-
"check-rollup-globals": "ts-node --project scripts/ scripts/check-rollup-globals.ts"
38+
"check-rollup-globals": "ts-node --project scripts/ scripts/check-rollup-globals.ts",
39+
"ownerslint": "ts-node --project scripts/ scripts/ownerslint.ts",
40+
"tslint": "tslint -c tslint.json --project ./tsconfig.json",
41+
"stylelint": "stylelint \"src/**/*.+(css|scss)\" --config .stylelintrc.json --syntax scss"
3942
},
4043
"version": "9.0.0-next.1",
4144
"requiredAngularVersion": "^9.0.0-0 || ^10.0.0-0",

scripts/ownerslint.ts

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import chalk from 'chalk';
2+
import {readdirSync, readFileSync, statSync} from 'fs';
3+
import {IMinimatch, Minimatch} from 'minimatch';
4+
import {join} from 'path';
5+
6+
/**
7+
* Script that lints the CODEOWNERS file and makes sure that all files have an owner.
8+
*/
9+
10+
/** Path for the Github owners file. */
11+
const ownersFilePath = '.github/CODEOWNERS';
12+
13+
/** Path for the .gitignore file. */
14+
const gitIgnorePath = '.gitignore';
15+
16+
let errors = 0;
17+
const ownedPaths = readFileSync(ownersFilePath, 'utf8').split('\n')
18+
// Trim lines.
19+
.map(line => line.trim())
20+
// Remove empty lines and comments.
21+
.filter(line => line && !line.startsWith('#'))
22+
// Split off just the path glob.
23+
.map(line => line.split(/\s+/)[0])
24+
// Turn paths into Minimatch objects.
25+
.map(path => new Minimatch(path, {dot: true, matchBase: true}));
26+
27+
const ignoredPaths = readFileSync(gitIgnorePath, 'utf8').split('\n')
28+
// Trim lines.
29+
.map(line => line.trim())
30+
// Remove empty lines and comments.
31+
.filter(line => line && !line.startsWith('#'))
32+
// Turn paths into Minimatch objects.
33+
.map(path => new Minimatch(path, {dot: true, matchBase: true}));
34+
35+
for (let paths = getChildPaths('.'); paths.length;) {
36+
paths = Array.prototype.concat(...paths
37+
// Remove ignored paths
38+
.filter(path => !ignoredPaths.reduce(
39+
(isIgnored, ignoredPath) => isIgnored || ignoredPath.match('/' + path), false))
40+
// Remove paths that match an owned path.
41+
.filter(path => !ownedPaths.reduce(
42+
(isOwned, ownedPath) => isOwned || isOwnedBy(path, ownedPath), false))
43+
// Report an error for any files that didn't match any owned paths.
44+
.filter(path => {
45+
if (statSync(path).isFile()) {
46+
console.log(chalk.red(`No code owner found for "${path}".`));
47+
errors++;
48+
return false;
49+
}
50+
return true;
51+
})
52+
// Get the next level of children for any directories.
53+
.map(path => getChildPaths(path)));
54+
}
55+
56+
if (errors) {
57+
throw Error(`Found ${errors} files with no owner. Code owners for the files ` +
58+
`should be added in the CODEOWNERS file.`);
59+
}
60+
61+
/** Check if the given path is owned by the given owned path matcher. */
62+
function isOwnedBy(path: string, ownedPath: IMinimatch) {
63+
// If the owned path ends with `**` its safe to eliminate whole directories.
64+
if (ownedPath.pattern.endsWith('**') || statSync(path).isFile()) {
65+
return ownedPath.match('/' + path);
66+
}
67+
return false;
68+
}
69+
70+
/** Get the immediate child paths of the given path. */
71+
function getChildPaths(path: string) {
72+
return readdirSync(path).map(child => join(path, child));
73+
}

tools/gulp/gulpfile.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import './tasks/ci';
2525
import './tasks/clean';
2626
import './tasks/default';
2727
import './tasks/example-module';
28-
import './tasks/lint';
2928
import './tasks/material-release';
3029
import './tasks/unit-test';
3130

tools/gulp/tasks/ci.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import {task} from 'gulp';
22

3-
task('ci:lint', ['lint']);
4-
53
// Gulp sometimes does not exit properly on CI. This is to prevent that.
64
// TODO(devversion): look if there is some blocking child process.
75
task('ci:test', ['test:single-run'], () => process.exit(0));

tools/gulp/tasks/lint.ts

Lines changed: 0 additions & 92 deletions
This file was deleted.

tslint.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"rulesDirectory": [
33
"./tools/tslint-rules/",
4+
"node_modules/vrsource-tslint-rules/rules",
45
"node_modules/codelyzer"
56
],
67
"rules": {

0 commit comments

Comments
 (0)