Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🏗 During PR checks, lint only the files in the PR, and flag errors instead of warnings #15256

Merged
merged 5 commits into from
May 14, 2018
Merged

🏗 During PR checks, lint only the files in the PR, and flag errors instead of warnings #15256

merged 5 commits into from
May 14, 2018

Conversation

rsimha
Copy link
Contributor

@rsimha rsimha commented May 13, 2018

There are upwards of 1300 JSDoc errors in the AMP source code. There's no easy way to fix all of them in one go.

This PR changes the way gulp lint works during PR checks and when it is run locally via gulp lint --files or as part of gulp pr-check:

  1. During PR checks and local runs of gulp pr-check, instead of linting the entire code base, we now lint only the JS files touched by the PR, with file-level exemptions in place.
  2. For the categories of lint errors that haven't been fully fixed and were therefore only showing as warnings, we now flag errors during PR checks via the rules in .eslint-strict.
  3. The behavior during push builds remains unchanged.

With this, if someone were to touch a file, they will be required to fix the existing JSDoc errors before gulp lint will pass for the PR check. This way, widespread errors in our code will be gradually fixed as more files are touched.

Partial fix for #15255
Required in order to fix #14392
Required in order to fix #10277
Follow up to #15247

@rsimha rsimha self-assigned this May 13, 2018
@rsimha rsimha requested review from jridgewell and dreamofabear May 13, 2018 22:05
@rsimha
Copy link
Contributor Author

rsimha commented May 13, 2018

@rsimha rsimha changed the title 🏗 During PR checks, flag all JSDoc lint errors in files touched by the PR 🏗 During PR checks, lint only the files in the PR, and flag errors instead of warnings May 13, 2018
.eslintrc Outdated
@@ -123,6 +123,12 @@
"space-in-parens": 2,
"space-infix-ops": 2,
"space-unary-ops": [1, { "words": true, "nonwords": false }],
"valid-jsdoc": [1, {
"requireParamDescription": false,
Copy link
Contributor

@jridgewell jridgewell May 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add:

"prefer": { "return": "return" }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

.eslintrc Outdated
"valid-jsdoc": [1, {
"requireParamDescription": false,
"requireReturn": false,
"requireReturnType": false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be true, right? We always want return types, if there's a return tag.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. Fixed.

// Override .eslintrc settings here.
options['rules'] = {
// TODO(rsimha, #15255): This should error by default in .eslintrc.
'valid-jsdoc': 2,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This removes the options we passed to the eslint configuration.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@rsimha
Copy link
Contributor Author

rsimha commented May 14, 2018

@jridgewell Comments addressed. PTAL.

const filesInPr =
getStdout('git diff --name-only master...HEAD').trim().split('\n');
return filesInPr.filter(function(file) {
return path.extname(file) == '.js';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a future change, do you mind adding '.ts' to this list or making a utility method the build process uses for filtering files based on extension?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion. Assuming it makes sense to run eslint checks on .ts files, we should definitely include them in gulp lint. Will test this out via a separate PR (there are other places that need to change too, so it's kinda out of scope for this PR.)

@kristoferbaxter
Copy link
Contributor

Might be naïve of me, but if an export changes shape during a PR would other files need to be verified that leverage the exported object?

@rsimha
Copy link
Contributor Author

rsimha commented May 14, 2018

@kristoferbaxter You're right that a change to an export will affect other files. Those checks are already incorporated in gulp check-types and gulp dep-check. This check is merely a per-file lint check, so I think it's safe (and fair) to run it only on the files contained in a PR.

@kristoferbaxter
Copy link
Contributor

Thanks @rsimha. Looks good to me.

// Override .eslintrc settings here.
options['rules'] = {
// TODO(rsimha, #15255): Make this error by default in .eslintrc.
'valid-jsdoc': [2, {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could instead maintain this as a second .eslintrc (let's say, .eslintrc-strict) with an extends option pointing to the default `.eslintrc. Then, switch to using the strict version for PRs.

This moves this configuration out of JavaScript code.

Copy link
Contributor Author

@rsimha rsimha May 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 0dee7f0

@dreamofabear
Copy link

I bet a lot of these are line breaks within a type definition. Closure Compiler doesn't seem to mind but VSCode and GitHub barf on them.

@rsimha
Copy link
Contributor Author

rsimha commented May 14, 2018

@choumx You may be right about line breaks within a type definition. However, I saw errors due to line breaks before type definitions that were being completely hidden from gulp check-types. For example, see #14439 (comment)

Fixes coming up.

@rsimha
Copy link
Contributor Author

rsimha commented May 14, 2018

@jridgewell Changes made. PTAL.

@rsimha rsimha merged commit 63b30a5 into ampproject:master May 14, 2018
@rsimha rsimha deleted the 2018-05-13-EslintWarnings branch May 14, 2018 23:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Master feature] Leaner AMP Significantly speed up gulp dist
5 participants