-
Notifications
You must be signed in to change notification settings - Fork 3.4k
build: configure ESLint coverage for gulp, scripts, docs, config #11064
Conversation
@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.
|
docs/app/js/.eslintrc.json
Outdated
@@ -0,0 +1,274 @@ | |||
{ | |||
"extends": "eslint:recommended", |
There was a problem hiding this comment.
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)
docs/app/js/.eslintrc.json
Outdated
"CryptoJS": true, | ||
"hljs": true | ||
}, | ||
"overrides": [ |
There was a problem hiding this comment.
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'.
There was a problem hiding this comment.
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!
docs/app/js/highlight-angular.js
Outdated
@@ -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, '') |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
docs/config/index.js
Outdated
@@ -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("/","-")}', |
There was a problem hiding this comment.
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("/","-")}` }
src/.eslintrc.json
Outdated
@@ -0,0 +1,273 @@ | |||
{ | |||
"extends": "eslint:recommended", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here, use 'overrides'
scripts/write-presubmit-scheduler.js
Outdated
@@ -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 |
There was a problem hiding this comment.
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 @@ | |||
|
There was a problem hiding this comment.
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`,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
updateVersionPicker.js
Outdated
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)); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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'.
@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. |
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. |
74be5f9
to
32eb3d5
Compare
879822d
to
d6668a7
Compare
.eslintrc.json
Outdated
@@ -1,271 +1,312 @@ | |||
{ | |||
"extends": "eslint:recommended", |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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;
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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;
There was a problem hiding this comment.
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.
gulp/tasks/karma-fast.js
Outdated
@@ -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)); |
There was a problem hiding this comment.
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
)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, done. Pushing soon.
d6668a7
to
614e18e
Compare
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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could probably be eslint .
There was a problem hiding this comment.
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/
?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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
614e18e
to
383738a
Compare
Makes sense.
…On 17 Jan 2018 11:29, "Michael Prentice" ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In .eslintignore
<#11064 (comment)>:
> @@ -0,0 +1,3 @@
+src/core/services/compiler/compiler.spec.js
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'.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#11064 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAZQTE5Nmw20METLMf_bVq7uyqHSutZ-ks5tLdmjgaJpZM4RcHuF>
.
|
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. |
PR Checklist
Please check that your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
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 inconfig/ 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?
Other information
N/A