Closed Bug 1245649 Opened 8 years ago Closed 8 years ago

Turn on more eslint rules in toolkit and browser

Categories

(Toolkit :: General, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla47
Tracking Status
firefox47 --- fixed

People

(Reporter: mossop, Assigned: mossop)

References

Details

Attachments

(9 files, 1 obsolete file)

58 bytes, text/x-review-board-request
Felipe
: review+
Details
58 bytes, text/x-review-board-request
Gijs
: review+
Details
58 bytes, text/x-review-board-request
Gijs
: review+
Details
58 bytes, text/x-review-board-request
markh
: review+
Details
58 bytes, text/x-review-board-request
Felipe
: review+
Details
58 bytes, text/x-review-board-request
jaws
: review+
Details
58 bytes, text/x-review-board-request
MattN
: review+
Details
58 bytes, text/x-review-board-request
MattN
: review+
Details
58 bytes, text/x-review-board-request
mconley
: review+
Details
      No description provided.
Comment on attachment 8715508 [details]
MozReview Request: Bug 1245649: Merge browser and toolkit eslint rule settings. r=felipe

Review request updated; see interdiff: https://reviewboard.mozilla.org/r/33487/diff/1-2/
Comment on attachment 8715508 [details]
MozReview Request: Bug 1245649: Merge browser and toolkit eslint rule settings. r=felipe

Review request updated; see interdiff: https://reviewboard.mozilla.org/r/33487/diff/2-3/
Comment on attachment 8715661 [details]
MozReview Request: Bug 1245649: Turn on no-trailing-spaces. r=Gijs

Review request updated; see interdiff: https://reviewboard.mozilla.org/r/33587/diff/1-2/
Comment on attachment 8715662 [details]
MozReview Request: Bug 1245649: Turn on linebreak-style. r=Gijs

Review request updated; see interdiff: https://reviewboard.mozilla.org/r/33589/diff/1-2/
Comment on attachment 8715663 [details]
MozReview Request: Bug 1245649: Turn on no-extra-semi. r=markh

Review request updated; see interdiff: https://reviewboard.mozilla.org/r/33591/diff/1-2/
Comment on attachment 8715664 [details]
MozReview Request: Bug 1245649: Turn on valid-typeof, no-invalid-regexp, no-empty-pattern and no-empty-character-class. r=felipe

Review request updated; see interdiff: https://reviewboard.mozilla.org/r/33593/diff/1-2/
Comment on attachment 8715665 [details]
MozReview Request: Bug 1245649: Turn on no-irregular-whitespace and no-mixed-spaces-and-tabs.

Review request updated; see interdiff: https://reviewboard.mozilla.org/r/33595/diff/1-2/
Comment on attachment 8715666 [details]
MozReview Request: Bug 1245649: Turn on no-irregular-whitespace and no-mixed-spaces-and-tabs. r=jaws

Review request updated; see interdiff: https://reviewboard.mozilla.org/r/33597/diff/1-2/
Comment on attachment 8715667 [details]
MozReview Request: Bug 1245649: Turn on use-isnan, no-unexpected-multiline, no-octal and no-self-compare. r=MattN

Review request updated; see interdiff: https://reviewboard.mozilla.org/r/33599/diff/1-2/
Comment on attachment 8715668 [details]
MozReview Request: Bug 1245649: Enable no-negated-in-lhs, no-native-reassign, no-func-assign and no-labels. r=MattN

Review request updated; see interdiff: https://reviewboard.mozilla.org/r/33601/diff/1-2/
Comment on attachment 8715669 [details]
MozReview Request: Bug 1245649: Enable no-nested-ternary.

Review request updated; see interdiff: https://reviewboard.mozilla.org/r/33603/diff/1-2/
Attachment #8715508 - Flags: review?(felipc)
Attachment #8715661 - Flags: review?(gijskruitbosch+bugs)
Attachment #8715662 - Flags: review?(gijskruitbosch+bugs)
Attachment #8715663 - Flags: review?(markh)
Attachment #8715664 - Flags: review?(felipc)
Attachment #8715665 - Flags: review?(jaws)
Attachment #8715666 - Flags: review?(jaws)
Attachment #8715667 - Flags: review?(MattN+bmo)
Attachment #8715668 - Flags: review?(MattN+bmo)
Attachment #8715669 - Flags: review?(mconley)
Comment on attachment 8715667 [details]
MozReview Request: Bug 1245649: Turn on use-isnan, no-unexpected-multiline, no-octal and no-self-compare. r=MattN

https://reviewboard.mozilla.org/r/33599/#review30407
Attachment #8715667 - Flags: review?(MattN+bmo) → review+
Attachment #8715665 - Flags: review?(jaws) → review+
Comment on attachment 8715665 [details]
MozReview Request: Bug 1245649: Turn on no-irregular-whitespace and no-mixed-spaces-and-tabs.

https://reviewboard.mozilla.org/r/33595/#review30411

Mossop said that `hg diff -w` reports no changes, and I trust eslint to detect any erroneous whitespace changes. rs=me
Attachment #8715666 - Flags: review?(jaws) → review+
Comment on attachment 8715666 [details]
MozReview Request: Bug 1245649: Turn on no-irregular-whitespace and no-mixed-spaces-and-tabs. r=jaws

https://reviewboard.mozilla.org/r/33597/#review30413

LGTM
Comment on attachment 8715668 [details]
MozReview Request: Bug 1245649: Enable no-negated-in-lhs, no-native-reassign, no-func-assign and no-labels. r=MattN

https://reviewboard.mozilla.org/r/33601/#review30415
Attachment #8715668 - Flags: review?(MattN+bmo) → review+
Attachment #8715663 - Flags: review?(markh) → review+
Comment on attachment 8715663 [details]
MozReview Request: Bug 1245649: Turn on no-extra-semi. r=markh

https://reviewboard.mozilla.org/r/33591/#review30417

Awesome!
Comment on attachment 8715661 [details]
MozReview Request: Bug 1245649: Turn on no-trailing-spaces. r=Gijs

https://reviewboard.mozilla.org/r/33587/#review30409

::: toolkit/components/console/content/consoleBindings.xml:393
(Diff revision 2)
>            

Might as well remove this while we're here... I'm assuming this isn't being seen because the transforms we do on XBL don't leave in the empty lines between methods?

::: toolkit/components/places/Bookmarks.jsm:696
(Diff revision 2)
> -          `INSERT OR IGNORE INTO moz_places (url, rev_host, hidden, frecency, guid) 
> +          `INSERT OR IGNORE INTO moz_places (url, rev_host, hidden, frecency, guid)

Note that this changes the string we're using here (and elsewhere in this file).

I believe that this is OK because there's still a boatload of whitespace between this and the VALUES clause later in the SQL statement, but it will lose us identity with earlier slow sql statement things. Likely fine, just something to watch out for when replacing whitespace in files as there could conceivably be less innocuous cases.

In fact, there's an argument to be made that the eslint thing should not complain about such trailing spacing inside template strings.

::: toolkit/content/widgets/radio.xml:195
(Diff revision 2)
>        

Nit: kill this too

::: toolkit/content/widgets/toolbar.xml:95
(Diff revision 2)
>    

and some more

::: toolkit/content/widgets/tree.xml:1323
(Diff revision 2)
>          ]]></body>        

and more

::: toolkit/content/widgets/tree.xml:1381
(Diff revision 2)
>          ]]></body>        

and more

::: toolkit/content/widgets/wizard.xml:171
(Diff revision 2)
>         

and in this binding
Attachment #8715661 - Flags: review?(gijskruitbosch+bugs) → review+
Comment on attachment 8715662 [details]
MozReview Request: Bug 1245649: Turn on linebreak-style. r=Gijs

https://reviewboard.mozilla.org/r/33589/#review30421
Attachment #8715662 - Flags: review?(gijskruitbosch+bugs) → review+
Comment on attachment 8715508 [details]
MozReview Request: Bug 1245649: Merge browser and toolkit eslint rule settings. r=felipe

https://reviewboard.mozilla.org/r/33487/#review30423
Attachment #8715508 - Flags: review?(felipc) → review+
Comment on attachment 8715664 [details]
MozReview Request: Bug 1245649: Turn on valid-typeof, no-invalid-regexp, no-empty-pattern and no-empty-character-class. r=felipe

https://reviewboard.mozilla.org/r/33593/#review30425
Attachment #8715664 - Flags: review?(felipc) → review+
https://reviewboard.mozilla.org/r/33587/#review30409

> Might as well remove this while we're here... I'm assuming this isn't being seen because the transforms we do on XBL don't leave in the empty lines between methods?

Yeah, eslint only sees the JS pieces of the XBL and even then we're fairly aggressive at stripping leading and trailing whitespace of that since it is often used to lining up XML tags so there are a few cases that eslint will miss trailing whitespace in those cases.

> Note that this changes the string we're using here (and elsewhere in this file).
> 
> I believe that this is OK because there's still a boatload of whitespace between this and the VALUES clause later in the SQL statement, but it will lose us identity with earlier slow sql statement things. Likely fine, just something to watch out for when replacing whitespace in files as there could conceivably be less innocuous cases.
> 
> In fact, there's an argument to be made that the eslint thing should not complain about such trailing spacing inside template strings.

Yeah I had seen the change and surmised like you that it wouldn't change the effect because there is still whitespace to the rest of the SQL. I hadn't considered the slow sql thing but I don't think it should matter.
Attachment #8715508 - Attachment description: MozReview Request: Bug 1245649: Merge browser and toolkit eslint rule settings. → MozReview Request: Bug 1245649: Merge browser and toolkit eslint rule settings. r=felipe
Comment on attachment 8715508 [details]
MozReview Request: Bug 1245649: Merge browser and toolkit eslint rule settings. r=felipe

Review request updated; see interdiff: https://reviewboard.mozilla.org/r/33487/diff/3-4/
Comment on attachment 8715661 [details]
MozReview Request: Bug 1245649: Turn on no-trailing-spaces. r=Gijs

Review request updated; see interdiff: https://reviewboard.mozilla.org/r/33587/diff/2-3/
Attachment #8715661 - Attachment description: MozReview Request: Bug 1245649: Turn on no-trailing-spaces → MozReview Request: Bug 1245649: Turn on no-trailing-spaces. r=Gijs
Comment on attachment 8715662 [details]
MozReview Request: Bug 1245649: Turn on linebreak-style. r=Gijs

Review request updated; see interdiff: https://reviewboard.mozilla.org/r/33589/diff/2-3/
Attachment #8715662 - Attachment description: MozReview Request: Bug 1245649: Turn on linebreak-style. → MozReview Request: Bug 1245649: Turn on linebreak-style. r=Gijs
Comment on attachment 8715663 [details]
MozReview Request: Bug 1245649: Turn on no-extra-semi. r=markh

Review request updated; see interdiff: https://reviewboard.mozilla.org/r/33591/diff/2-3/
Attachment #8715663 - Attachment description: MozReview Request: Bug 1245649: Turn on no-extra-semi. → MozReview Request: Bug 1245649: Turn on no-extra-semi. r=markh
Comment on attachment 8715664 [details]
MozReview Request: Bug 1245649: Turn on valid-typeof, no-invalid-regexp, no-empty-pattern and no-empty-character-class. r=felipe

Review request updated; see interdiff: https://reviewboard.mozilla.org/r/33593/diff/2-3/
Attachment #8715664 - Attachment description: MozReview Request: Bug 1245649: Turn on valid-typeof, no-invalid-regexp, no-empty-pattern and no-empty-character-class → MozReview Request: Bug 1245649: Turn on valid-typeof, no-invalid-regexp, no-empty-pattern and no-empty-character-class. r=felipe
Comment on attachment 8715666 [details]
MozReview Request: Bug 1245649: Turn on no-irregular-whitespace and no-mixed-spaces-and-tabs. r=jaws

Review request updated; see interdiff: https://reviewboard.mozilla.org/r/33597/diff/2-3/
Attachment #8715666 - Attachment description: MozReview Request: Bug 1245649: Turn on no-irregular-whitespace and no-mixed-spaces-and-tabs. → MozReview Request: Bug 1245649: Turn on no-irregular-whitespace and no-mixed-spaces-and-tabs. r=jaws
Comment on attachment 8715667 [details]
MozReview Request: Bug 1245649: Turn on use-isnan, no-unexpected-multiline, no-octal and no-self-compare. r=MattN

Review request updated; see interdiff: https://reviewboard.mozilla.org/r/33599/diff/2-3/
Attachment #8715667 - Attachment description: MozReview Request: Bug 1245649: Turn on use-isnan, no-unexpected-multiline, no-octal and no-self-compare. → MozReview Request: Bug 1245649: Turn on use-isnan, no-unexpected-multiline, no-octal and no-self-compare. r=MattN
Comment on attachment 8715668 [details]
MozReview Request: Bug 1245649: Enable no-negated-in-lhs, no-native-reassign, no-func-assign and no-labels. r=MattN

Review request updated; see interdiff: https://reviewboard.mozilla.org/r/33601/diff/2-3/
Attachment #8715668 - Attachment description: MozReview Request: Bug 1245649: Enable no-negated-in-lhs, no-native-reassign, no-func-assign and no-labels. → MozReview Request: Bug 1245649: Enable no-negated-in-lhs, no-native-reassign, no-func-assign and no-labels. r=MattN
Comment on attachment 8715669 [details]
MozReview Request: Bug 1245649: Enable no-nested-ternary.

Review request updated; see interdiff: https://reviewboard.mozilla.org/r/33603/diff/2-3/
Attachment #8715665 - Attachment is obsolete: true
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Comment on attachment 8715669 [details]
MozReview Request: Bug 1245649: Enable no-nested-ternary.

https://reviewboard.mozilla.org/r/33603/#review30555

Thanks Mossop! Great job. I will not be sorry to see these things go.

::: browser/base/content/browser-gestureSupport.js:429
(Diff revision 3)
> -      let getFunc = "get" + (type == "boolean" ? "Bool" :
> -                             type == "number" ? "Int" : "Char") + "Pref";
> -      return gPrefService[getFunc](branch + aPref);
> +      let getFunc = "Char";
> +      if (type == "boolean")
> +        getFunc = "Bool";
> +      else if (type == "number")
> +        getFunc = "Int";

I'll assume at this point, we haven't turned on the rule for "always braces around one-liner conditionals". :)

::: browser/extensions/pocket/content/pktApi.jsm:545
(Diff revision 3)
> -                    return a < b ? -1 : a > b ? 1 : 0;
> +                    return a - b;

Mossop++ for grand simplification.

::: toolkit/.eslintrc:112
(Diff revision 3)
>      // Nested ternary statements are confusing

You got that right.

::: toolkit/components/places/PlacesBackups.jsm:176
(Diff revision 3)
> -      return aDate < bDate ? 1 : aDate > bDate ? -1 : 0;
> +      return bDate.getTime() - aDate.getTime();

Do we really need .getTime() here?

::: toolkit/components/places/PlacesBackups.jsm:218
(Diff revision 3)
> -        return aDate < bDate ? 1 : aDate > bDate ? -1 : 0;
> +        return bDate.getTime() - aDate.getTime();

Same a above - doesn't just taking the deltas between Date's work, or am I missing something?

::: toolkit/components/reader/Readability.js:750
(Diff revision 3)
> -          var scoreDivider = level === 0 ? 1 : level === 1 ? 2 : level * 3;
> +          var scoreDivider = level < 2 ? level + 1 : level * 3;

Another great simplification.

::: toolkit/modules/Geometry.jsm:265
(Diff revision 3)
> -    let offsetX = (this.left <= other.left ? other.left - this.left :
> -                  (this.right > other.right ? other.right - this.right : 0));
> -    let offsetY = (this.top <= other.top ? other.top - this.top :
> -                  (this.bottom > other.bottom ? other.bottom - this.bottom : 0));
> +    let offsetX = 0;
> +    if (this.left <= other.left)
> +      offsetX = other.left - this.left;
> +    else if (this.right > other.right)
> +      offsetX = other.right - this.right;
> +    let offsetY = 0;
> +    if (this.top <= other.top)
> +      offsetY = other.top - this.top;
> +    else if (this.bottom > other.bottom)
> +      offsetY = other.bottom - this.bottom;

Nit: Maybe just break up the two blocks for offsetX and offsetY with a newline above 270.
Attachment #8715669 - Flags: review?(mconley) → review+
https://reviewboard.mozilla.org/r/33603/#review30555

> I'll assume at this point, we haven't turned on the rule for "always braces around one-liner conditionals". :)

We haven't, that's going to be a fun one to turn on, you're welcome to try!

> Do we really need .getTime() here?

You're right, I didn't know Date objects worked like that.
https://hg.mozilla.org/mozilla-central/rev/f9181d9e2a6e
Status: REOPENED → RESOLVED
Closed: 8 years ago8 years ago
Resolution: --- → FIXED
This changed readability to use `let`.

The canonical readability repo is on github, and we can't use `let` there for compat reasons.

I'll probably land a workaround there to continue to use |var| and still not redeclare anything, and then merge that back into m-c.

Should we just ignore these files or enable a very limited set of rules in them or something? What would be the best way to deal with this?
Flags: needinfo?(felipc)
Flags: needinfo?(dtownsend)
(In reply to :Gijs Kruitbosch from comment #48)
> This changed readability to use `let`.
> 
> The canonical readability repo is on github, and we can't use `let` there
> for compat reasons.

Sorry, didn't realise that was external code.

> I'll probably land a workaround there to continue to use |var| and still not
> redeclare anything, and then merge that back into m-c.
> 
> Should we just ignore these files or enable a very limited set of rules in
> them or something? What would be the best way to deal with this?

My general preference is just to add any code that we import wholesale from elsewhere to the ignore list so we're not spending time trying to fix things for their choices. If an external project has eslint set up and uses an eslintignore for example it will get ignored when imported so we'd start to see failures.
Flags: needinfo?(felipc)
Flags: needinfo?(dtownsend)
(In reply to Dave Townsend [:mossop] from comment #49)
> (In reply to :Gijs Kruitbosch from comment #48)
> > This changed readability to use `let`.
> > 
> > The canonical readability repo is on github, and we can't use `let` there
> > for compat reasons.
> 
> Sorry, didn't realise that was external code.
> 
> > I'll probably land a workaround there to continue to use |var| and still not
> > redeclare anything, and then merge that back into m-c.
> > 
> > Should we just ignore these files or enable a very limited set of rules in
> > them or something? What would be the best way to deal with this?
> 
> My general preference is just to add any code that we import wholesale from
> elsewhere to the ignore list so we're not spending time trying to fix things
> for their choices. If an external project has eslint set up and uses an
> eslintignore for example it will get ignored when imported so we'd start to
> see failures.

I wrote an .eslintrc for readability on github (https://github.com/mozilla/readability/pull/270 ) and added es6-disabling comments at the beginning of the files in question, but adding the specific files to eslintignore sounds good, so I'll land that in a bit.
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: