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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
}],
"object-shorthand": 2,
"one-var": [2, "never"],
"prefer-const": 2,
"prefer-template": 2,
"quote-props": [1, "consistent-as-needed"],
"quotes": [2, "single", "avoid-escape"],
Expand Down
12 changes: 6 additions & 6 deletions src/cmd/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,23 +104,23 @@ async function defaultPackageCreator({
manifestData = await getValidatedManifest(sourceDir);
}

let buffer = await zipDir(sourceDir, {
const buffer = await zipDir(sourceDir, {
filter: (...args) => fileFilter.wantFile(...args),
});

let extensionName: string = manifestData.name;

if (manifestData.default_locale) {
let messageFile = path.join(sourceDir, '_locales',
const messageFile = path.join(sourceDir, '_locales',
manifestData.default_locale, 'messages.json');
log.debug('Manifest declared default_locale, localizing extension name');
extensionName = await getDefaultLocalizedName(
{messageFile, manifestData});
}
let packageName = safeFileName(
const packageName = safeFileName(
`${extensionName}-${manifestData.version}.zip`);
let extensionPath = path.join(artifactsDir, packageName);
let stream = createWriteStream(extensionPath);
const extensionPath = path.join(artifactsDir, packageName);
const stream = createWriteStream(extensionPath);

stream.write(buffer, () => stream.end());

Expand Down Expand Up @@ -166,7 +166,7 @@ export default async function build(
});

await prepareArtifactsDir(artifactsDir);
let result = await createPackage();
const result = await createPackage();

if (rebuildAsNeeded) {
log.info('Rebuilding when files change...');
Expand Down
16 changes: 7 additions & 9 deletions src/cmd/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,15 @@ export function defaultReloadStrategy(
createWatcher = defaultWatcherCreator,
}: ReloadStrategyOptions = {}
): void {
let watcher: Watchpack;
const watcher: Watchpack = (
createWatcher({addonId, client, sourceDir, artifactsDir})
);

firefoxProcess.on('close', () => {
client.disconnect();
watcher.close();
});

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


Expand Down Expand Up @@ -181,15 +182,12 @@ export default async function run(
const requiresRemote = !preInstall;
let installed = false;

let runner;
let profile;
let client;
let runningFirefox;
let addonId;

let manifestData = await getValidatedManifest(sourceDir);
const manifestData = await getValidatedManifest(sourceDir);

runner = new ExtensionRunner({
const runner = new ExtensionRunner({
sourceDir,
firefoxApp,
firefox,
Expand All @@ -198,7 +196,7 @@ export default async function run(
customPrefs,
});

profile = await runner.getProfile();
const profile = await runner.getProfile();

if (!preInstall) {
log.debug('Deferring extension installation until after ' +
Expand All @@ -209,7 +207,7 @@ export default async function run(
installed = true;
}

runningFirefox = await runner.run(profile);
const runningFirefox = await runner.run(profile);

if (installed) {
log.debug('Not installing as temporary add-on because the ' +
Expand Down
6 changes: 3 additions & 3 deletions src/cmd/sign.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default function sign(
manifestData = await getValidatedManifest(sourceDir);
}

let [buildResult, idFromSourceDir] = await Promise.all([
const [buildResult, idFromSourceDir] = await Promise.all([
build({sourceDir, artifactsDir: tmpDir.path()},
{manifestData, showReadyMessage: false}),
getIdFromSourceDir(sourceDir),
Expand Down Expand Up @@ -93,7 +93,7 @@ export default function sign(
log.warn('No extension ID specified (it will be auto-generated)');
}

let signingResult = await signAddon({
const signingResult = await signAddon({
apiKey,
apiSecret,
apiUrlPrefix,
Expand Down Expand Up @@ -152,7 +152,7 @@ export async function getIdFromSourceDir(
}
});

let id = lines[0];
const id = lines[0];
log.debug(`Found extension ID ${id} in ${filePath}`);

if (!id) {
Expand Down
6 changes: 3 additions & 3 deletions src/firefox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export function configureProfile(
): Promise<FirefoxProfile> {
// Set default preferences. Some of these are required for the add-on to
// operate, such as disabling signatures.
let prefs = getPrefs(app);
const prefs = getPrefs(app);
Object.keys(prefs).forEach((pref) => {
profile.setPreference(pref, prefs[pref]);
});
Expand Down Expand Up @@ -283,8 +283,8 @@ export async function copyProfile(
}: CopyProfileOptions = {},
): Promise<FirefoxProfile> {

let copy = promisify(FirefoxProfile.copy);
let copyByName = promisify(copyFromUserProfile);
const copy = promisify(FirefoxProfile.copy);
const copyByName = promisify(copyFromUserProfile);

try {
const dirExists = await isDirectory(profileDirectory);
Expand Down
9 changes: 6 additions & 3 deletions src/firefox/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,17 @@ export function getPrefs(
export function coerceCLICustomPreference(
cliPrefs: string | Array<string>
): FirefoxPreferences {
let customPrefs = {};
const customPrefs = {};

if (!Array.isArray(cliPrefs)) {
cliPrefs = [cliPrefs];
}

for (let pref of cliPrefs) {
let [key, value] = pref.split('=');

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

if (/[^\w{@}.-]/.test(key)) {
throw new UsageError(`Invalid custom preference name: ${key}`);
Expand Down
2 changes: 1 addition & 1 deletion src/firefox/remote.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export class RemoteFirefox {
const response = await this.addonRequest(addon, 'requestTypes');

if (response.requestTypes.indexOf('reload') === -1) {
let supportedRequestTypes = JSON.stringify(response.requestTypes);
const supportedRequestTypes = JSON.stringify(response.requestTypes);
log.debug(
`Remote Firefox only supports: ${supportedRequestTypes}`);
throw new UsageError(
Expand Down
6 changes: 3 additions & 3 deletions src/program.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class Program {
// Command line option (pref) renamed for internal use (customPref).
argv.customPrefs = argv.pref;

let runCommand = this.commands[cmd];
const runCommand = this.commands[cmd];

if (argv.verbose) {
logStream.makeVerbose();
Expand Down Expand Up @@ -147,7 +147,7 @@ export function defaultVersionGetter(
): string {
if (localEnv === 'production') {
log.debug('Getting the version from package.json');
let packageData: any = readFileSync(
const packageData: any = readFileSync(
path.join(absolutePackageDir, 'package.json'));
return JSON.parse(packageData).version;
} else {
Expand All @@ -164,7 +164,7 @@ export function main(
runOptions = {},
}: Object = {}
): Promise<any> {
let program = new Program(argv, {absolutePackageDir});
const program = new Program(argv, {absolutePackageDir});
// yargs uses magic camel case expansion to expose options on the
// final argv object. For example, the 'artifacts-dir' option is alternatively
// available as argv.artifactsDir.
Expand Down
2 changes: 1 addition & 1 deletion src/util/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class ConsoleStream {
}

flushCapturedLogs({localProcess = process}: ConsoleOptions = {}) {
for (let msg of this.capturedMessages) {
for (const msg of this.capturedMessages) {
localProcess.stdout.write(msg);
}
this.capturedMessages = [];
Expand Down
4 changes: 2 additions & 2 deletions src/util/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export type ExtensionManifest = {|
export default async function getValidatedManifest(
sourceDir: string
): Promise<ExtensionManifest> {
let manifestFile = path.join(sourceDir, 'manifest.json');
const manifestFile = path.join(sourceDir, 'manifest.json');
log.debug(`Validating manifest at ${manifestFile}`);

let manifestContents;
Expand All @@ -52,7 +52,7 @@ export default async function getValidatedManifest(
`Error parsing manifest.json at ${manifestFile}: ${error}`);
}

let errors = [];
const errors = [];
// This is just some basic validation of what web-ext needs, not
// what Firefox will need to run the extension.
// TODO: integrate with the addons-linter for actual validation.
Expand Down
6 changes: 3 additions & 3 deletions src/util/temp-dir.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const log = createLogger(__filename);
*
*/
export function withTempDir(makePromise: Function): Promise<any> {
let tmpDir = new TempDir();
const tmpDir = new TempDir();
return tmpDir.create()
.then(() => {
return makePromise(tmpDir);
Expand Down Expand Up @@ -62,15 +62,15 @@ export class TempDir {
* been created.
*/
create(): Promise<TempDir> {
let createTempDir = promisify(tmp.dir, {multiArgs: true});
const createTempDir = promisify(tmp.dir, {multiArgs: true});
return createTempDir(
{
prefix: 'tmp-web-ext-',
// This allows us to remove a non-empty tmp dir.
unsafeCleanup: true,
})
.then((args) => {
let [tmpPath, removeTempDir] = args;
const [tmpPath, removeTempDir] = args;
this._path = tmpPath;
this._removeTempDir = removeTempDir;
log.debug(`Created temporary directory: ${this.path()}`);
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/test.cli.lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('web-ext lint', () => {
it('should accept: --source-dir SRCDIR',
() => withTempAddonDir({addonPath}, (srcDir, tmpDir) => {
const argv = ['lint', '--source-dir', srcDir, '--verbose'];
let cmd = execCommand(webExt, argv, {cwd: tmpDir});
const cmd = execCommand(webExt, argv, {cwd: tmpDir});

return cmd.waitForExit.then(({exitCode, stdout, stderr}) => {
if (exitCode !== 0) {
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,11 @@ export function fake<T>(original: Object, methods: Object = {}): T {
}

var proto = Object.getPrototypeOf(original);
for (let key of props) {
for (const key of props) {
if (!original.hasOwnProperty(key) && !proto.hasOwnProperty(key)) {
continue;
}
let definition = original[key] || proto[key];
const definition = original[key] || proto[key];
if (typeof definition === 'function') {
stub[key] = () => {
log.warn(`Running stubbed function ${key} (default implementation)`);
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/test-cmd/test.build.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const log = createLogger(__filename);
describe('build', () => {

it('zips a package', () => {
let zipFile = new ZipFile();
const zipFile = new ZipFile();

return withTempDir(
(tmpDir) =>
Expand Down Expand Up @@ -201,8 +201,8 @@ describe('build', () => {
));

it('asks FileFilter what files to include in the ZIP', () => {
let zipFile = new ZipFile();
let fileFilter = new FileFilter({
const zipFile = new ZipFile();
const fileFilter = new FileFilter({
filesToIgnore: ['**/background-script.js'],
});

Expand Down
10 changes: 5 additions & 5 deletions tests/unit/test-cmd/test.run.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ describe('run', () => {

function prepareRun(fakeInstallResult) {
const sourceDir = fixturePath('minimal-web-ext');
let argv = {
const argv = {
artifactsDir: path.join(sourceDir, 'web-ext-artifacts'),
sourceDir,
noReload: true,
};
let options = {
const options = {
firefoxApp: getFakeFirefox(),
firefoxClient: sinon.spy(() => {
return Promise.resolve(fake(RemoteFirefox.prototype, {
Expand All @@ -63,8 +63,8 @@ describe('run', () => {
}

function getFakeFirefox(implementations = {}) {
let profile = {}; // empty object just to avoid errors.
let allImplementations = {
const profile = {}; // empty object just to avoid errors.
const allImplementations = {
createProfile: () => Promise.resolve(profile),
copyProfile: () => Promise.resolve(profile),
installExtension: () => Promise.resolve(),
Expand All @@ -76,7 +76,7 @@ describe('run', () => {

it('installs and runs the extension', () => {

let profile = {};
const profile = {};

const cmd = prepareRun();
const {firefoxApp} = cmd.options;
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/test-cmd/test.sign.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ describe('sign', () => {

it('returns a signing result', () => withTempDir(
(tmpDir) => {
let stubs = getStubs();
const stubs = getStubs();
return sign(tmpDir, stubs)
.then((realResult) => {
assert.deepEqual(realResult, stubs.signingResult);
Expand Down Expand Up @@ -267,7 +267,7 @@ describe('sign', () => {
return sign(tmpDir, stubs, {extraArgs: {artifactsDir}})
.then(() => {
assert.equal(stubs.signAddon.called, true);
let signedAddonCall = stubs.signAddon.firstCall.args[0];
const signedAddonCall = stubs.signAddon.firstCall.args[0];
assert.equal(signedAddonCall.apiKey,
stubs.signingConfig.apiKey);
assert.equal(signedAddonCall.apiSecret,
Expand All @@ -294,7 +294,7 @@ describe('sign', () => {

it('passes the verbose flag to the signer', () => withTempDir(
(tmpDir) => {
let stubs = getStubs();
const stubs = getStubs();
return sign(tmpDir, stubs, {extraArgs: {verbose: true}})
.then(() => {
assert.equal(stubs.signAddon.called, true);
Expand All @@ -305,7 +305,7 @@ describe('sign', () => {

it('passes through a signing exception', () => withTempDir(
(tmpDir) => {
let stubs = getStubs();
const stubs = getStubs();
stubs.signAddon = () => Promise.reject(new Error('some signing error'));

return sign(tmpDir, stubs)
Expand Down
Loading