Skip to content

Commit

Permalink
Enable indentation linting
Browse files Browse the repository at this point in the history
  • Loading branch information
sneakypete81 committed Feb 13, 2019
1 parent 98cbe52 commit 89ec21f
Show file tree
Hide file tree
Showing 20 changed files with 442 additions and 428 deletions.
8 changes: 6 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ module.exports = {
'no-console': 'off',
// Don't prohibit whitespace around code blocks
'padded-blocks': 'off',
// Don't enforce 4-space line continuation indent
'indent': 0,
// Preferred indentation rules
'indent': ['error', 2, {
'FunctionExpression': {'parameters': 'first'},
'SwitchCase': 1,
'VariableDeclarator': 1,
}],
// Downgrade JSDoc requirement to a warning
'require-jsdoc': 'warn',
// Use @returns if the function returns
Expand Down
12 changes: 6 additions & 6 deletions scripts/rename-signed-xpi.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ const oldSuffix = '-an+fx.xpi';
const newSuffix = '-an.fx.xpi';

exports.rename = function() {
for (const file of fs.readdirSync('dist')) {
if (file.endsWith(oldSuffix)) {
const newFile = file.replace(oldSuffix, newSuffix);
fs.renameSync('dist/' + file, 'dist/' + newFile);
console.log('Renamed to ' + newFile);
}
for (const file of fs.readdirSync('dist')) {
if (file.endsWith(oldSuffix)) {
const newFile = file.replace(oldSuffix, newSuffix);
fs.renameSync('dist/' + file, 'dist/' + newFile);
console.log('Renamed to ' + newFile);
}
}
};
13 changes: 7 additions & 6 deletions src/lib/page/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ export class Page {
* than NO_CHANGE or CHANGE indicates an error.
*/
static get stateEnum() {
return {NO_CHANGE: 'no_change',
CHANGED: 'changed',
ERROR: 'error',
};
return {
NO_CHANGE: 'no_change',
CHANGED: 'changed',
ERROR: 'error',
};
}

/**
Expand Down Expand Up @@ -160,7 +161,7 @@ export class Page {
lastAutoscanTime: this.lastAutoscanTime,
oldScanTime: this.oldScanTime,
newScanTime: this.newScanTime,
};
};
}

/**
Expand All @@ -185,7 +186,7 @@ export class Page {
// lastAutoscanTime: this.lastAutoscanTime,
// oldScanTime: this.oldScanTime,
// newScanTime: this.newScanTime,
};
};
}

/**
Expand Down
11 changes: 6 additions & 5 deletions src/lib/page/page_folder.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ export class PageFolder {
* @returns {Object} Enumeration of PageFolder change states.
*/
static get stateEnum() {
return {NO_CHANGE: 'no_change',
CHANGED: 'changed',
};
return {
NO_CHANGE: 'no_change',
CHANGED: 'changed',
};
}

/**
Expand Down Expand Up @@ -86,7 +87,7 @@ export class PageFolder {
title: this.title,
state: this.state,
children: this.children,
};
};
}

/**
Expand All @@ -99,7 +100,7 @@ export class PageFolder {
title: this.title,
// state: this.state,
// children: this.children,
};
};
}

/**
Expand Down
11 changes: 6 additions & 5 deletions src/lib/page/storage_info.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,12 @@ export class StorageInfo {
* @returns {Object} Object suitable for storage.
*/
_toObject() {
return {version: this.version,
pageIds: this.pageIds,
pageFolderIds: this.pageFolderIds,
nextId: this.nextId,
};
return {
version: this.version,
pageIds: this.pageIds,
pageFolderIds: this.pageFolderIds,
nextId: this.nextId,
};
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/lib/scan/fuzzy.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ function firstDifference(str1, str2) {
const minlen = Math.min(str1.length, str2.length);

for (let i = 0; i < minlen; i++) {
if (str1[i] != str2[i]) {
return i;
}
if (str1[i] != str2[i]) {
return i;
}
}
return minlen;
}
2 changes: 1 addition & 1 deletion src/lib/util/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
*
* @param {string} message - Message to log.
*/
export function log(message) {
export function log(message) {
console.log(message);
}
4 changes: 2 additions & 2 deletions test/unit/autoscan_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ describe('Autoscan', function() {
});
const pageNotToScan = new Page(2, {
url: 'http://test.com',
scanRateMinutes: 30,
lastAutoscanTime: Date.now(),
scanRateMinutes: 30,
lastAutoscanTime: Date.now(),
});
const pages = [pageToScan, pageNotToScan];
spyOn(this.pageStore, 'getPageList').and.returnValues(pages);
Expand Down
18 changes: 9 additions & 9 deletions test/unit/config_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ describe('Config', function() {
});

it('loads a config setting from storage with chained construction',
function(done) {
spyOn(Storage, 'load').and.returnValues(Promise.resolve({debug: true}));

new Config().load().then((config) => {
expect(Storage.load).toHaveBeenCalledWith('config');
expect(config.get('debug')).toEqual(true);
done();
}).catch((error) => done.fail(error));
});
function(done) {
spyOn(Storage, 'load').and.returnValues(Promise.resolve({debug: true}));

new Config().load().then((config) => {
expect(Storage.load).toHaveBeenCalledWith('config');
expect(config.get('debug')).toEqual(true);
done();
}).catch((error) => done.fail(error));
});
});

describe('save', function() {
Expand Down
4 changes: 2 additions & 2 deletions test/unit/fuzzy_changed_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe('fuzzy', function() {
], function(data) {
it('returns ' + data.major + ' when ' + data.slice + ' characters are ' +
'changed at the middle with threshold=' + data.threshold,
function() {
function() {
const html1 = readFixtures('amo.html');
const html2 = html1.slice(0, data.pos) +
Array(data.slice + 1).join('d') +
Expand All @@ -92,7 +92,7 @@ describe('fuzzy', function() {
], function(data) {
it('returns ' + data.major + ' when ' + data.slice + ' characters are ' +
'changed at two places with threshold=' + data.threshold,
function() {
function() {
const html1 = readFixtures('amo.html');
const html2 = html1.slice(0, data.pos1) +
Array(data.slice + 1).join('d') +
Expand Down
4 changes: 2 additions & 2 deletions test/unit/fuzzy_inserted_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe('fuzzy', function() {
], function(data) {
it('returns ' + data.major + ' when ' + data.slice + ' characters are ' +
'inserted at the middle with threshold=' + data.threshold,
function() {
function() {
const html1 = readFixtures('amo.html');
const html2 = html1.slice(0, data.pos) +
Array(data.slice + 1).join('d') +
Expand All @@ -91,7 +91,7 @@ describe('fuzzy', function() {
], function(data) {
it('returns ' + data.major + ' when ' + data.slice + ' characters are ' +
'inserted at two places with threshold=' + data.threshold,
function() {
function() {
const html1 = readFixtures('amo.html');
const html2 = html1.slice(0, data.pos1) +
Array(data.slice + 1).join('d') +
Expand Down
4 changes: 2 additions & 2 deletions test/unit/fuzzy_removed_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe('fuzzy', function() {
], function(data) {
it('returns ' + data.major + ' when ' + data.slice + ' characters are ' +
'removed from the middle with threshold=' + data.threshold,
function() {
function() {
const html1 = readFixtures('amo.html');
const html2 = html1.slice(0, data.pos) +
html1.slice(data.pos + data.slice);
Expand All @@ -90,7 +90,7 @@ describe('fuzzy', function() {
], function(data) {
it('returns ' + data.major + ' when ' + data.slice + ' characters are ' +
'removed from two places with threshold=' + data.threshold,
function() {
function() {
const html1 = readFixtures('amo.html');
const html2 = html1.slice(0, data.pos1) +
html1.slice(data.pos1 + data.slice, data.pos2) +
Expand Down
38 changes: 19 additions & 19 deletions test/unit/main_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,27 @@ describe('Main', function() {

describe('_showDiff', function() {
it('Updates the view with a diff of the old and new HTML from storage',
function(done) {
const id = '42';
const page = new Page(id, {url: 'test.com/blah'});
const html = 'hello';
const main = new Main();

spyOn(StorageDB, 'load').and.returnValue(Promise.resolve(html));
spyOn(mainModule.__, 'diff').and.returnValues('diffHtml');
spyOn(mainModule.__, 'viewDiff').and.callFake((pageArg, htmlArg) => {
expect(htmlArg).toEqual(
'<base href="test.com/blah" target="_top">diffHtml');
expect(pageArg).toEqual(page);
expect(StorageDB.load).toHaveBeenCalledWith('html:old:' + id);
expect(StorageDB.load).toHaveBeenCalledWith('html:new:' + id);
expect(mainModule.__.diff).toHaveBeenCalledWith(page, html, html);
done();
function(done) {
const id = '42';
const page = new Page(id, {url: 'test.com/blah'});
const html = 'hello';
const main = new Main();

spyOn(StorageDB, 'load').and.returnValue(Promise.resolve(html));
spyOn(mainModule.__, 'diff').and.returnValues('diffHtml');
spyOn(mainModule.__, 'viewDiff').and.callFake((pageArg, htmlArg) => {
expect(htmlArg).toEqual(
'<base href="test.com/blah" target="_top">diffHtml');
expect(pageArg).toEqual(page);
expect(StorageDB.load).toHaveBeenCalledWith('html:old:' + id);
expect(StorageDB.load).toHaveBeenCalledWith('html:new:' + id);
expect(mainModule.__.diff).toHaveBeenCalledWith(page, html, html);
done();
});

main._showDiff(page);
});

main._showDiff(page);
});

it('logs to the console if the page\'s html isn\'t found', function(done) {
const page = new Page(42, {url: 'test.com/blah'});
const main = new Main();
Expand Down
72 changes: 37 additions & 35 deletions test/unit/page_folder_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ describe('PageFolder', function() {
describe('load', function() {
it('loads a PageFolder from storage', function(done) {
const id = '42';
const data = {title: 'Folder Title',
state: PageFolder.stateEnum.CHANGED,
children: ['1', '2', '3'],
};
const data = {
title: 'Folder Title',
state: PageFolder.stateEnum.CHANGED,
children: ['1', '2', '3'],
};
spyOn(Storage, 'load').and.returnValues(Promise.resolve(data));

PageFolder.load(id).then((pageFolder) => {
Expand All @@ -19,52 +20,53 @@ describe('PageFolder', function() {
expect(pageFolder.children).toEqual(data.children);
done();
})
.catch((error) => done.fail(error));
.catch((error) => done.fail(error));
});

it('returns the default PageFolder if there is no object in storage',
function(done) {
spyOn(Storage, 'load').and.returnValues(Promise.resolve(undefined));
function(done) {
spyOn(Storage, 'load').and.returnValues(Promise.resolve(undefined));

PageFolder.load('42').then((pageFolder) => {
expect(pageFolder.title).toEqual('New Folder');
expect(pageFolder.children).toEqual([]);
done();
})
.catch((error) => done.fail(error));
});
PageFolder.load('42').then((pageFolder) => {
expect(pageFolder.title).toEqual('New Folder');
expect(pageFolder.children).toEqual([]);
done();
})
.catch((error) => done.fail(error));
});

it('returns the default PageFolder if the storage load fails',
function(done) {
spyOn(Storage, 'load').and
.returnValues(Promise.reject(new Error('ERROR_MESSAGE')));
spyOn(pageFolderModule.__, 'log');

PageFolder.load('42').then((pageFolder) => {
expect(pageFolder.title).toEqual('New Folder');
expect(pageFolderModule.__.log.calls.argsFor(0))
.toMatch('ERROR_MESSAGE');
done();
})
.catch((error) => done.fail(error));
});
function(done) {
spyOn(Storage, 'load').and
.returnValues(Promise.reject(new Error('ERROR_MESSAGE')));
spyOn(pageFolderModule.__, 'log');

PageFolder.load('42').then((pageFolder) => {
expect(pageFolder.title).toEqual('New Folder');
expect(pageFolderModule.__.log.calls.argsFor(0))
.toMatch('ERROR_MESSAGE');
done();
})
.catch((error) => done.fail(error));
});
});

describe('save', function() {
it('saves a PageFolder to storage', function(done) {
spyOn(Storage, 'save').and.returnValues(Promise.resolve());
const id = 33;
const data = {title: 'A PageFolder',
state: PageFolder.stateEnum.CHANGED,
children: ['23', '34'],
};
const data = {
title: 'A PageFolder',
state: PageFolder.stateEnum.CHANGED,
children: ['23', '34'],
};
const pageFolder = new PageFolder(id, data);

pageFolder.save().then(() => {
expect(Storage.save).toHaveBeenCalledWith(PageFolder._KEY(id), data);
done();
})
.catch((error) => done.fail(error));
.catch((error) => done.fail(error));
});

it('silently logs an error if the save fails', function(done) {
Expand All @@ -76,7 +78,7 @@ describe('PageFolder', function() {
expect(pageFolderModule.__.log.calls.argsFor(0)).toMatch('AN_ERROR');
done();
})
.catch((error) => done.fail(error));
.catch((error) => done.fail(error));
});
});

Expand All @@ -91,7 +93,7 @@ describe('PageFolder', function() {
PageFolder._KEY(pageFolder.id));
done();
})
.catch((error) => done.fail(error));
.catch((error) => done.fail(error));
});

it('silently logs an error if the delete operation fails', function(done) {
Expand All @@ -105,7 +107,7 @@ describe('PageFolder', function() {
expect(pageFolderModule.__.log.calls.argsFor(0)).toMatch('AN_ERROR');
done();
})
.catch((error) => done.fail(error));
.catch((error) => done.fail(error));
});
});

Expand Down
Loading

0 comments on commit 89ec21f

Please sign in to comment.