Skip to content

Commit b567c1e

Browse files
committed
feat: make lint check opt-in
Disable lint check by default and make it opt-in, so it doesn't impact the workflow for collaborators, while providing a way for early birds to try it out so we can tweak it until it works great for everyone (at which point we can re-enable it by default). Ref: nodejs#484
1 parent 17ea885 commit b567c1e

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

components/git/land.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ const landOptions = {
4848
default: false,
4949
type: 'boolean'
5050
},
51+
lint: {
52+
describe: 'Run linter while landing commits',
53+
default: false,
54+
type: 'boolean'
55+
},
5156
autorebase: {
5257
describe: 'Automatically rebase branches with multiple commits',
5358
default: false,
@@ -99,8 +104,8 @@ function handler(argv) {
99104

100105
const provided = [];
101106
for (const type of Object.keys(landOptions)) {
102-
// --yes and --skipRefs are not actions.
103-
if (type === 'yes' || type === 'skipRefs') continue;
107+
// Those are not actions.
108+
if (['yes', 'skipRefs', 'lint'].includes(type)) continue;
104109
if (argv[type]) {
105110
provided.push(type);
106111
}
@@ -171,7 +176,7 @@ async function main(state, argv, cli, req, dir) {
171176
return;
172177
}
173178
session = new LandingSession(cli, req, dir, argv.prid, argv.backport,
174-
argv.autorebase);
179+
argv.lint, argv.autorebase);
175180
const metadata = await getMetadata(session.argv, argv.skipRefs, cli);
176181
if (argv.backport) {
177182
const split = metadata.metadata.split('\n')[0];

lib/landing_session.js

+19-7
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,25 @@ const { shortSha } = require('./utils');
1515

1616
const isWindows = process.platform === 'win32';
1717

18+
const LINT_RESULTS = {
19+
SKIPPED: 'skipped',
20+
FAILED: 'failed',
21+
SUCCESS: 'success'
22+
};
23+
1824
class LandingSession extends Session {
19-
constructor(cli, req, dir, prid, backport, autorebase) {
25+
constructor(cli, req, dir, prid, backport, lint, autorebase) {
2026
super(cli, dir, prid);
2127
this.req = req;
2228
this.backport = backport;
29+
this.lint = lint;
2330
this.autorebase = autorebase;
2431
}
2532

2633
get argv() {
2734
const args = super.argv;
2835
args.backport = this.backport;
36+
args.lint = this.lint;
2937
args.autorebase = this.autorebase;
3038
return args;
3139
}
@@ -147,14 +155,18 @@ class LandingSession extends Session {
147155
async validateLint() {
148156
// The linter is currently only run on non-Windows platforms.
149157
if (os.platform() === 'win32') {
150-
return true;
158+
return LINT_RESULTS.SKIPPED;
159+
}
160+
161+
if (!this.lint) {
162+
return LINT_RESULTS.SKIPPED;
151163
}
152164

153165
try {
154166
await runAsync('make', ['lint']);
155-
return true;
167+
return LINT_RESULTS.SUCCESS;
156168
} catch {
157-
return false;
169+
return LINT_RESULTS.FAILED;
158170
}
159171
}
160172

@@ -229,13 +241,13 @@ class LandingSession extends Session {
229241
const patch = await this.downloadAndPatch();
230242

231243
const cleanLint = await this.validateLint();
232-
if (!cleanLint) {
244+
if (cleanLint === LINT_RESULTS.FAILED) {
233245
const tryFixLint = await cli.prompt(
234246
'Lint failed - try fixing with \'make lint-js-fix\'?');
235247
if (tryFixLint) {
236248
await runAsync('make', ['lint-js-fix']);
237249
const fixed = await this.validateLint();
238-
if (!fixed) {
250+
if (fixed === LINT_RESULTS.FAILED) {
239251
cli.warn('Patch still contains lint errors. ' +
240252
'Please fix manually before proceeding');
241253
}
@@ -253,7 +265,7 @@ class LandingSession extends Session {
253265
'`git node land --continue`.');
254266
process.exit(1);
255267
}
256-
} else {
268+
} else if (cleanLint === LINT_RESULTS.SUCCESS) {
257269
cli.ok('Lint passed cleanly');
258270
}
259271

0 commit comments

Comments
 (0)