Skip to content
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

fix: Added prefer-const to eslint and related changes #700

Merged
merged 4 commits into from
Dec 22, 2016

Conversation

aniketkudale
Copy link
Contributor

Fixes #640

@aniketkudale
Copy link
Contributor Author

Hi @kumar303, sorry for new PR, I messed up in my previous PR so closed that one. Also, the test for commit 6b47da4 was successful on my machine, dont know why it is failing on travis-ci. Once again thanks for taking time for reviewing.

@shubheksha
Copy link
Contributor

Hi @aniketkudale, Travis is complaining because the commit message of your second commit doesn't follow format mentioned in the contributing guide.

@aniketkudale
Copy link
Contributor Author

Ah, thanks. Noted :)

@aniketkudale aniketkudale changed the title fix: Added prefer-const rule to eslint changes fix: Added prefer-const to eslint and related changes Dec 21, 2016
Copy link
Contributor

@kumar303 kumar303 left a comment

Choose a reason for hiding this comment

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

Thanks for following up. This looks great, just one more change request.

let watcher: Watchpack;
const watcher: Watchpack = (
createWatcher({addonId, client, sourceDir, artifactsDir})
);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is indented too far. It should look like this:

const watcher: Watchpack = (
  createWatcher({addonId, client, sourceDir, artifactsDir})
);

This provides a visual indication to the reader that the block is connected to the line opening with const watcher....

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks a lot @kumar303 I'll update the change.

@kumar303
Copy link
Contributor

In regards to the commit message formatting problem, are you using git commit --no-verify ? Because git should not let you commit with a message formatted this way. Be sure all your local dependencies are up to date by running npm install.

@aniketkudale
Copy link
Contributor Author

Actually I am using Tortoise SVN tool for commits, so may be this is causing the problem.

@kumar303
Copy link
Contributor

Huh, seems like that should work. I see that TortoiseGit has custom hooks but I don't see why it would ignore our git hooks.

@kumar303
Copy link
Contributor

Let me know if you need help fixing the Flow errors

@kumar303 kumar303 self-assigned this Dec 21, 2016
@aniketkudale
Copy link
Contributor Author

Yes, please! This looks interesting. Neither of cmds, npm run build and npm run lint, throw any warning on my machine.

@aniketkudale
Copy link
Contributor Author

aniketkudale commented Dec 21, 2016

@kumar303 Will it be ok to use var, this doesnt give any warnings/error on npm run build and npm run lint

  for (const pref of cliPrefs) {
    var [key, value] = pref.split('='); // using var here, line 137 (src\firefox\preferences.js)

    if (/[^\w{@}.-]/.test(key)) {
      throw new UsageError(`Invalid custom preference name: ${key}`);
    }

    if (value === `${parseInt(value)}`) {
      value = parseInt(value, 10);
    } else if (value === 'true' || value === 'false') {
      value = (value === 'true');
}

@kumar303
Copy link
Contributor

Hi, thanks for the quick response.

Neither of cmds, npm run build andnpm run lint, throw any warning on my machine.

You should be using the npm start command to develop with. When you get a chance, please read through the development process to get familiar with it: https://github.com/mozilla/web-ext/blob/master/CONTRIBUTING.md

Will it be ok to use var?

All variables that do not get modified must be declared with const. For any variable that needs to be modified, use let because it deals with scoping better than var. But, yes, the problem you are running into is that you changed a variable from let to const but that variable is getting modified so it can't be a constant.

@aniketkudale
Copy link
Contributor Author

aniketkudale commented Dec 22, 2016

oh, @kumar303 so can we write
const [key value] = pref.split('=');
as

const [key] = pref.split('=');
let [value] = pref.split('=');

@rpl
Copy link
Member

rpl commented Dec 22, 2016

@aniketkudale you should be able to rewrite it as:

const prefsAry = pref.split('=');
const [key] = prefsAry;
let [, value] = prefsAry;

The comma (,) in second line means that you want to skip the first element and assign the second one to value.

Nevertheless, I'm not sure that it is very readable written in this way, I would not be against using the regular syntax in this case, eg.:

const prefsAry = pref.split('=');
const key = prefsAry[0];
let value = prefsAry[1];

@aniketkudale
Copy link
Contributor Author

Thanks @rpl for reply.

const prefsAry = pref.split('=');
const key = prefsAry[0];
let value = prefsAry[1];

This looks readable & simple to understand.

@coveralls
Copy link

coveralls commented Dec 22, 2016

Coverage Status

Coverage remained the same at 100.0% when pulling 7e8b20f on aniketkudale:pref-const-fix into 5e47787 on mozilla:master.

Copy link
Contributor

@kumar303 kumar303 left a comment

Choose a reason for hiding this comment

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

Thanks! This style check will be very helpful for other contributors. You can ignore the changelog lint failures, we'll be fixing that in #701

@kumar303 kumar303 merged commit dbdf9e2 into mozilla:master Dec 22, 2016
@aniketkudale
Copy link
Contributor Author

Thanks a lot @kumar303 for merging my PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants