Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

build: configure ESLint coverage for gulp, scripts, docs, config #11064

Merged
merged 1 commit into from
Jan 18, 2018

Conversation

Splaktar
Copy link
Member

PR Checklist

Please check that your PR fulfills the following requirements:

  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

[ ] Bugfix
[ ] Feature
[x] Code style update (formatting, local variables)
[x] Refactoring (no functional changes, no api changes)
[x] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] Infrastructure changes
[ ] Other... Please describe:

What is the current behavior?

Currently none of the repository is linted with ESLint except for src/. This means that all of the scripts and code in config/ docs/ gulp/ scripts/ is not covered. This code contains quite a wide range of bad practices. Additionally, there is an informal mix of ES5 and ES6 in the repository.

configure parts of the repo for ES5 (src, docs/app/js)
configure parts of the repo for ES6 (scripts, gulp, config, root)
remove unused committers.json
clean up ESLint errors
some minor ES6 updates and refactoring outside of src/

Issue Number:
N/A

What is the new behavior?

Add linting coverage for the vast majority of the repository.
Explicitly configure different sections of the repo for ES5 or ES6 and run linting to verify that no crossover violations occur (breaking browser support).

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Other information

N/A

@Splaktar Splaktar added this to the 1.1.6 milestone Jan 12, 2018
@googlebot googlebot added the cla: yes PR author has signed Google's CLA: https://opensource.google.com/docs/cla/ label Jan 12, 2018
@Splaktar Splaktar added type: build needs: review This PR is waiting on review from the team type: refactor labels Jan 12, 2018
@Splaktar Splaktar requested a review from devversion January 12, 2018 10:50
@Splaktar
Copy link
Member Author

Splaktar commented Jan 12, 2018

@graingert As you implemented the initial ESLint support and have another ESLint PR in flight, can you please take a look at this PR and suggest any possible improvements or best practices for configuring ESLint.

I put this together while reviewing all of the tooling and scripting in the project so that I could better understand it prior to putting out the 1.1.6 release.

  • Run all of the gulp tasks successfully
  • Manually test and verify that the docs site functioned and looks as expected
  • Run the release script in dryRun mode and verify that it completes properly
  • Run npm run lint and verify that there are no failures

@@ -0,0 +1,274 @@
{
"extends": "eslint:recommended",
Copy link
Contributor

Choose a reason for hiding this comment

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

eslint configs are automatically inherited up the directory tree. So you can remove duplicate rules.

Aaaalso you can use the "overrides" param in the root .eslintrc. (prefered)

"CryptoJS": true,
"hljs": true
},
"overrides": [
Copy link
Contributor

Choose a reason for hiding this comment

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

eg this overrides list can add an object with files: ["docs/"] configured for 'docs'.

Copy link
Member Author

Choose a reason for hiding this comment

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

I see that overrides is an array... oh and it has a seperate rules, globals, and env that applies to that set of files. Oh very nice. Then I can do it all in that one file, excellent. I'll work on merging things together. Thank you!

@@ -53,6 +53,7 @@ angular.module('docsApp')

var highlightedCode = hljs.highlight(attr.language || attr.lang, lines.join('\n'), true);
highlightedCode.value = highlightedCode.value
// eslint-disable-next-line no-div-regex
.replace(/=<span class="hljs-value">""<\/span>/gi, '')
Copy link
Contributor

Choose a reason for hiding this comment

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

should be possible to do \= here

Copy link
Member Author

Choose a reason for hiding this comment

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

That gives me no-useless-escape error. I think that I am just going to disable no-div-regex globally.

@@ -42,6 +42,7 @@ module.exports = new Package('angular-md', [

computeIdsProcessor.idTemplates.push({
docTypes: ['content'],
// eslint-disable-next-line no-template-curly-in-string
idTemplate: 'content-${fileInfo.relativePath.replace("/","-")}',
Copy link
Contributor

@graingert graingert Jan 12, 2018

Choose a reason for hiding this comment

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

idTemplate: { getId: ({ fileInfo }) => `content-${fileInfo.relativePath.replace("/","-")}` }

@@ -0,0 +1,273 @@
{
"extends": "eslint:recommended",
Copy link
Contributor

Choose a reason for hiding this comment

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

same here, use 'overrides'

@@ -19,6 +19,7 @@ const logDir = '/tmp/v1-pr-presubmit-logs';
* The default path is stored in an environment variable because it references an internal-Google
* location.
*/
// eslint-disable-next-line no-process-env
Copy link
Contributor

Choose a reason for hiding this comment

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

ignore this in the 'scripts' overrides.

@@ -47,23 +44,20 @@

Copy link
Contributor

@graingert graingert Jan 12, 2018

Choose a reason for hiding this comment

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

just use

`cp -r ${docs.latest} latest`,

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

return str.replace(/\{\{[^\}]+\}\}/g, function (match) {
function fill (str) {
return str.replace(/{{[^}]+}}/g, function (match) {
// eslint-disable-next-line no-eval
return eval(match.substr(2, match.length - 4));
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of eval just use template string functions.

Copy link
Contributor

@graingert graingert Jan 12, 2018

Choose a reason for hiding this comment

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

actually this is only used for cp -r ${docs.latest} latest, so just totally not-needed.

@@ -0,0 +1,3 @@
src/core/services/compiler/compiler.spec.js
Copy link
Contributor

Choose a reason for hiding this comment

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

you could probably do these with the 'overrides' feature.

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried to add them to an excludedFiles array, but that didn't work. Most of them cause ESLint to actually throw a parsing error if the file is evaluated at all. Adding them to the ignore file avoided this issue.

Copy link
Contributor

Choose a reason for hiding this comment

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

test/ doesn't seem to have that much wrong with it. I suspect they can be added to the overrides.2.files array.

Copy link
Member Author

Choose a reason for hiding this comment

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

I started into cleaning those up and getting them passing, but there were a number of things that I am not comfortable changing at this time. I'd like to keep that as part of a separate PR since those files are actually used to test the library and changing them would make this PR no longer 'merge safe'.

@graingert
Copy link
Contributor

@Splaktar good idea to upgrade all the util scripts to modern js. Looks like there was a bit of a misunderstanding on how .eslintrc inheritance/overrides operates.

@Splaktar
Copy link
Member Author

Yep, thank you very much for the review. I had a feeling that it may have some inheritance features like TSLint, I just didn't have time to research every part of how it worked.

@Splaktar Splaktar removed the needs: review This PR is waiting on review from the team label Jan 13, 2018
@Splaktar Splaktar force-pushed the cleanupScripts branch 3 times, most recently from 879822d to d6668a7 Compare January 13, 2018 10:09
@Splaktar Splaktar added pr: merge ready This PR is ready for a caretaker to review pr: merge safe labels Jan 13, 2018
.eslintrc.json Outdated
@@ -1,271 +1,312 @@
{
"extends": "eslint:recommended",
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be convenient to not change the indenting in this PR so there's fewer rebase issues with my document/window PR, and so it's easier to review changes here.

Copy link
Member Author

Choose a reason for hiding this comment

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

You have a good point there. Can you please update your PR to use 2 spaces instead of 4? That should minimize most of it. I'm not sure if/when, we'll be able to get that in as it doesn't have non-zero risk. I would rather not keep this file using inconsistent 4 space formatting for an extended period of time.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure if/when, we'll be able to get that in as it doesn't have non-zero risk

as it has non-zero risk?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd be happy with the indent change happening in this PR as long as it's in one atomic commit at the end

Copy link
Contributor

Choose a reason for hiding this comment

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

It's currently impossible to review

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, I understand. That's the hard thing with the original formatting not being the same as the project. I guess it's using CLANG for formatting atm (which I don't actually use). I'm not sure why .editorconfig isn't used other than Google is used to CLANG. Either way, I don't have your original formatting settings. I'll set it back to 4 spaces and see how that looks.

Copy link
Member Author

Choose a reason for hiding this comment

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

Pushed. Yeah, the diff looks much better now. Please take a look.

gulp/config.js Outdated
@@ -1,5 +1,6 @@
var args = require('minimist')(process.argv.slice(2));
var VERSION = args.version || require('../package.json').version;
var version = require('../package.json').version;
var VERSION = args.version || version;
Copy link
Member

Choose a reason for hiding this comment

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

This is confusing and ambiguous. I'd prefer just inlining this.

var version = args.version || require('../package.json').version;

Copy link
Member

Choose a reason for hiding this comment

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

Also if you update it like that in the const.js file, you can just import the VERSION export here. This removes duplicate logic.

Copy link
Contributor

Choose a reason for hiding this comment

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

that breaks the top level require only rule.

Copy link
Contributor

@graingert graingert Jan 16, 2018

Choose a reason for hiding this comment

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

and you can't use any of the wacky conditional require stuff with esm, so it's good to require top level imports only.

maybe use:

const pkg = require('../package.json');

const VERSION = args.version || pkg.version;

Copy link
Member

@devversion devversion Jan 16, 2018

Choose a reason for hiding this comment

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

Yeah, the important thing is just that the version and VERSION names are way too similar and should be somehow differentiated.

@@ -30,14 +29,15 @@ exports.task = function (done) {

gutil.log('Running unit tests on unminified source.');

karma = new Server(karmaConfig, captureError(clearEnv,clearEnv));
var karma = new Server(karmaConfig, captureError(clearEnv,clearEnv));
Copy link
Member

Choose a reason for hiding this comment

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

Is it intended to use var here? It kind of feels inconsistent to me (why not const)

Copy link
Contributor

Choose a reason for hiding this comment

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

it's odd that it didn't complain.

Copy link
Member Author

Choose a reason for hiding this comment

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

I updated scripts/ but I didn't update all of the gulp tasks yet...

Copy link
Contributor

Choose a reason for hiding this comment

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

probably worth running the safe transforms

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, done. Pushing soon.

@Splaktar Splaktar modified the milestones: 1.1.6, 1.1.7 Jan 17, 2018
@Splaktar Splaktar added in progress Mainly for in progress PRs, but may be used for issues that require multiple PRs and removed pr: merge ready This PR is ready for a caretaker to review labels Jan 17, 2018
package.json Outdated
@@ -85,6 +85,6 @@
"docs:watch": "gulp watch site --dev",
"test:fast": "gulp karma-fast",
"test:full": "gulp karma",
"lint": "eslint src"
"lint": "eslint src docs gulp config scripts"
Copy link
Contributor

Choose a reason for hiding this comment

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

could probably be eslint .

Copy link
Member Author

Choose a reason for hiding this comment

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

Would that try to lint dist/?

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe eslint also uses .gitignore by default.

Copy link
Contributor

Choose a reason for hiding this comment

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

ah no it doesn't you need:

eslint . --ignore-path .gitignore --ignore-path .eslintignore

Copy link
Contributor

Choose a reason for hiding this comment

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

ah, it looks like you can't set two ignore files. Probably worth just adding dist to .eslintignore.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated and pushed.

configure parts of the repo for ES5 (src, docs/app/js)
configure parts of the repo for ES6 (scripts, gulp, config)
remove unused committers.json
clean up ESLint errors
@graingert
Copy link
Contributor

graingert commented Jan 17, 2018 via email

@Splaktar Splaktar added pr: merge ready This PR is ready for a caretaker to review and removed in progress Mainly for in progress PRs, but may be used for issues that require multiple PRs labels Jan 18, 2018
@Splaktar
Copy link
Member Author

I ran into some issues testing the build-contributors task. After debugging, it uncovered mgechev/github-contributors-list#12. I opened mgechev/github-contributors-list#13 to fix the issue.

This should be good to go now.

@josephperrott josephperrott merged commit 6e425c4 into angular:master Jan 18, 2018
@Splaktar Splaktar deleted the cleanupScripts branch January 27, 2018 07:17
chmelevskij pushed a commit to chmelevskij/material that referenced this pull request Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes PR author has signed Google's CLA: https://opensource.google.com/docs/cla/ pr: merge ready This PR is ready for a caretaker to review type: build
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants