-
Notifications
You must be signed in to change notification settings - Fork 150
Configure amo eslint config #1451
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
Configure amo eslint config #1451
Conversation
| 'https://foo.com', | ||
| 'ftp://do.people.still.use.this', | ||
| 'app://wat', | ||
| // FIXME: the loop in this test was previously broken. |
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 the bad loop that needs a bug filing to fix. The matchPattern seen in the test was always the last value in the list.
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.
r+wc
| "test": "jest tests/ --runInBand --coverage", | ||
| "test-no-coverage": "jest tests/ --runInBand", | ||
| "test-ci": "npm run test && cat ./coverage/lcov.info | coveralls", | ||
| "test": "jest tests/ --runInBand --watch", |
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 honestly not a fan of a default watch, can we maybe not do that? At least on my machine it's a constant memory leak
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 be good to get to the bottom of why that is. Not using watch defeats one of the best features of Jest.
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 suppose one of the other goals I was aiming for was to try and make the test command setup more consistent between addons-frontend and addons-linter since that's another difference we can eliminate.
If I added the test-once command would that provide what you need? See https://github.com/mozilla/addons-frontend/#development-commands for more details.
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've added yarn test-once and test-coverage-once.
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.
Perfect, thanks a lot! I think that works for me.
|
|
||
| checkPath(path) { | ||
| if (!this.files.hasOwnProperty(path)) { | ||
| if (!Object.prototype.hasOwnProperty.call(this.files, path)) { |
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.
what's the difference 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.
src/scanners/binary.js
Outdated
| for (let v in values) { | ||
| const valuesKeys = Object.keys(values); | ||
| for (let i = 0; i < valuesKeys.length; i++) { | ||
| const v = valuesKeys[i]; |
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.
why no forEach 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.
Because there's no way to break out of a forEach without throwing.
Thinking about it this is probably something where we could be using https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some
It could probably be re-written as:
if (Object.keys(values).some((v) => values[v] !== buffer[v])) {
return;
}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 going to switch this to use Array.prototype.some. It's purpose built for this use-case.
| new RegExp('browser/components/extensions/schemas/.*\.json'), | ||
| new RegExp('toolkit/components/extensions/schemas/.*\.json'), | ||
| new RegExp('browser/components/extensions/schemas/.*\\.json'), | ||
| new RegExp('toolkit/components/extensions/schemas/.*\\.json'), |
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.
great catch!
| for (var part of parts) { | ||
|
|
||
| for (let i = 0; i < parts.length; i++) { | ||
| let part = parts[i]; |
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 no forEach 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.
Same reason as before.
|
|
||
| describe('Xpi.getFilesByExt()', function() { | ||
|
|
||
| describe('Xpi.getFilesByExt()', function getFilesByExtCallback() { |
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.
Why are they named now? Can't we just use lambdas here as well, afair we do that quite often in other tests?
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.
One of the lint rules prevents unnamed functions. In our tests we have a few places where we rely on this, and the semantics of a fat arrow breaks that code from working . We should probably look at refactoring those tests and set consts instead of relying on this.
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.
FWIW, you could just create a nested ./tests/.eslintrc which disables that one unnamed function rule, and all the other rules from the root .eslintrc file would still be inherited.
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.
@pdehaan If we end up concluding we don't need the rule I'd rather disable it centrally in the shared config since we're trying to make our config more consistent across repos. Of course there might be some cases where we do need overrides but we'd probably want to keep that to an absolute minimum.
|
@EnTeQuAk if you're happy with this and want to land it feel free to go ahead and squash/merge it. Otherwise we can fix up any additional bits next week. |
|
Thank you so much for the explanations and work that went into this! This is looking great :) So I just merged this, if there's anything else that needs to be done I'm sure we can easily do it in a separate PR. |
Fixes #1450
Fixes #1391 (it made testing easier)
It found a couple of real issues:
browser/components/extensions/schemas/lkfjghdsfhskdjhfjsonand not justbrowser/components/extensions/schemas/lkfjghdsfhskdjhf.jsonA lot of the noise is spaces around
{etc.The bigger changes were changes to a lot of the loops to move away from
for..inandfor..of.There's a lot of changes here so it'll be worth trying to be diligent with review incase something got broken in the process.