Closed Bug 1218425 Opened 4 years ago Closed 4 years ago

ESLint rule that checks for aArgs in function parameters

Categories

(DevTools :: General, defect)

defect
Not set

Tracking

(firefox44 fixed)

RESOLVED FIXED
Firefox 44
Tracking Status
firefox44 --- fixed

People

(Reporter: pbro, Assigned: pbro)

References

Details

Attachments

(1 file, 1 obsolete file)

Our coding standards [1] warns against using aArgs, but we have plenty in our code already. An EsLint rule would be really simple to write and would help prevent adding more in the future.

[1] https://wiki.mozilla.org/DevTools/CodingStandards#Code_style
This should work nicely. Still have to do some more tests, but a first review would help confirm this rule is wanted.
Assignee: nobody → pbrosset
Status: NEW → ASSIGNED
Attachment #8678905 - Flags: review?(mratcliffe)
Comment on attachment 8678905 [details] [diff] [review]
Bug_1218425_-_ESLint_rule_that_warns_against_aArg_.diff

Review of attachment 8678905 [details] [diff] [review]:
-----------------------------------------------------------------

r+ with nits addressed

::: testing/eslint-plugin-mozilla/lib/rules/no-aArgs.js
@@ +19,5 @@
> +
> +  function isPrefixed(name) {
> +    return name.length >= 2 &&
> +           name.substring(0, 1) === "a" &&
> +           name.substring(1, 2).toUpperCase() === name.substring(1, 2);

It would be simpler to use:
return name.length >= 2 && /^a[A-Z]/.test(name);

@@ +24,5 @@
> +  }
> +
> +  function deHungarianize(name) {
> +    return name.substring(1, 2).toLowerCase() +
> +           name.substring(2, name.length);

It would be simpler to use:
return "aHello".substring(1).toLowerCase();
Attachment #8678905 - Flags: review?(mratcliffe) → review+
(In reply to Michael Ratcliffe [:miker] [:mratcliffe] from comment #2)
> ::: testing/eslint-plugin-mozilla/lib/rules/no-aArgs.js
> @@ +19,5 @@
> > +
> > +  function isPrefixed(name) {
> > +    return name.length >= 2 &&
> > +           name.substring(0, 1) === "a" &&
> > +           name.substring(1, 2).toUpperCase() === name.substring(1, 2);
> 
> It would be simpler to use:
> return name.length >= 2 && /^a[A-Z]/.test(name);
Good point, I will change this.

> @@ +24,5 @@
> > +  }
> > +
> > +  function deHungarianize(name) {
> > +    return name.substring(1, 2).toLowerCase() +
> > +           name.substring(2, name.length);
> 
> It would be simpler to use:
> return "aHello".substring(1).toLowerCase();
This would change "aCamelCasedName" to "camelcasedname" which isn't what we want. So I think I need to keep the slightly more complex form.
Built on top of bug 269836, so let's depend on it.
Depends on: 269836
Attachment #8678905 - Attachment is obsolete: true
Attachment #8679853 - Flags: review+
Keywords: checkin-needed
Depends on: 1218409
No longer depends on: 269836
https://hg.mozilla.org/mozilla-central/rev/f1cef30cb767
Status: ASSIGNED → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 44
Product: Firefox → DevTools
You need to log in before you can comment on or make changes to this bug.