Refactor code to comply with ESLint rules

Major refactoring using ESLint with rules from AirBnb and Vue.

Enable most of the ESLint rules and do necessary linting in the code.
Also add more information for rules that are disabled to describe what
they are and why they are disabled.

Allow logging (`console.log`) in test files, and in development mode
(e.g. when working with `npm run serve`), but disable it when
environment is production (as pre-configured by Vue). Also add flag
(`--mode production`) in `lint:eslint` command so production linting is
executed earlier in lifecycle.

Disable rules that requires a separate work. Such as ESLint rules that
are broken in TypeScript: no-useless-constructor (eslint/eslint#14118)
and no-shadow (eslint/eslint#13014).
This commit is contained in:
undergroundwires
2022-01-02 18:20:14 +01:00
parent 96265b75de
commit 5b1fbe1e2f
341 changed files with 16126 additions and 15101 deletions

View File

@@ -10,92 +10,94 @@ import { CategoryStub } from '@tests/unit/stubs/CategoryStub';
import { CategoryCollectionStub } from '@tests/unit/stubs/CategoryCollectionStub';
describe('CategoryCollectionState', () => {
describe('code', () => {
it('initialized with empty code', () => {
// arrange
const collection = new CategoryCollectionStub();
const sut = new CategoryCollectionState(collection);
// act
const code = sut.code.current;
// assert
expect(!code);
});
it('reacts to selection changes as expected', () => {
// arrange
const collection = new CategoryCollectionStub()
.withAction(new CategoryStub(0).withScriptIds('scriptId'));
const selectionStub = new UserSelection(collection, []);
const expectedCodeGenerator = new ApplicationCode(selectionStub, collection.scripting);
selectionStub.selectAll();
const expectedCode = expectedCodeGenerator.current;
// act
const sut = new CategoryCollectionState(collection);
sut.selection.selectAll();
const actualCode = sut.code.current;
// assert
expect(actualCode).to.equal(expectedCode);
});
describe('code', () => {
it('initialized with empty code', () => {
// arrange
const collection = new CategoryCollectionStub();
const sut = new CategoryCollectionState(collection);
// act
const code = sut.code.current;
// assert
expect(!code);
});
describe('os', () => {
it('same as its collection', () => {
// arrange
const expected = OperatingSystem.macOS;
const collection = new CategoryCollectionStub()
.withOs(expected);
// act
const sut = new CategoryCollectionState(collection);
// assert
const actual = sut.os;
expect(expected).to.equal(actual);
});
it('reacts to selection changes as expected', () => {
// arrange
const collection = new CategoryCollectionStub()
.withAction(new CategoryStub(0).withScriptIds('scriptId'));
const selectionStub = new UserSelection(collection, []);
const expectedCodeGenerator = new ApplicationCode(selectionStub, collection.scripting);
selectionStub.selectAll();
const expectedCode = expectedCodeGenerator.current;
// act
const sut = new CategoryCollectionState(collection);
sut.selection.selectAll();
const actualCode = sut.code.current;
// assert
expect(actualCode).to.equal(expectedCode);
});
describe('selection', () => {
it('initialized with no selection', () => {
// arrange
const collection = new CategoryCollectionStub();
const sut = new CategoryCollectionState(collection);
// act
const actual = sut.selection.selectedScripts.length;
// assert
expect(actual).to.equal(0);
});
it('can select a script from current collection', () => {
// arrange
const expectedScript = new ScriptStub('scriptId');
const collection = new CategoryCollectionStub()
.withAction(new CategoryStub(0).withScript(expectedScript));
const sut = new CategoryCollectionState(collection);
// act
sut.selection.selectAll();
// assert
expect(sut.selection.selectedScripts.length).to.equal(1);
expect(sut.selection.isSelected(expectedScript.id)).to.equal(true);
});
});
describe('os', () => {
it('same as its collection', () => {
// arrange
const expected = OperatingSystem.macOS;
const collection = new CategoryCollectionStub()
.withOs(expected);
// act
const sut = new CategoryCollectionState(collection);
// assert
const actual = sut.os;
expect(expected).to.equal(actual);
});
describe('filter', () => {
it('initialized with an empty filter', () => {
// arrange
const collection = new CategoryCollectionStub();
const sut = new CategoryCollectionState(collection);
// act
const actual = sut.filter.currentFilter;
// assert
expect(actual).to.equal(undefined);
});
it('can match a script from current collection', () => {
// arrange
const scriptNameFilter = 'scriptName';
const expectedScript = new ScriptStub('scriptId')
.withName(scriptNameFilter);
const collection = new CategoryCollectionStub()
.withAction(new CategoryStub(0).withScript(expectedScript));
const sut = new CategoryCollectionState(collection);
// act
let actualScript: IScript;
sut.filter.filtered.on((result) => actualScript = result.scriptMatches[0]);
sut.filter.setFilter(scriptNameFilter);
// assert
expect(expectedScript).to.equal(actualScript);
});
});
describe('selection', () => {
it('initialized with no selection', () => {
// arrange
const collection = new CategoryCollectionStub();
const sut = new CategoryCollectionState(collection);
// act
const actual = sut.selection.selectedScripts.length;
// assert
expect(actual).to.equal(0);
});
it('can select a script from current collection', () => {
// arrange
const expectedScript = new ScriptStub('scriptId');
const collection = new CategoryCollectionStub()
.withAction(new CategoryStub(0).withScript(expectedScript));
const sut = new CategoryCollectionState(collection);
// act
sut.selection.selectAll();
// assert
expect(sut.selection.selectedScripts.length).to.equal(1);
expect(sut.selection.isSelected(expectedScript.id)).to.equal(true);
});
});
describe('filter', () => {
it('initialized with an empty filter', () => {
// arrange
const collection = new CategoryCollectionStub();
const sut = new CategoryCollectionState(collection);
// act
const actual = sut.filter.currentFilter;
// assert
expect(actual).to.equal(undefined);
});
it('can match a script from current collection', () => {
// arrange
const scriptNameFilter = 'scriptName';
const expectedScript = new ScriptStub('scriptId')
.withName(scriptNameFilter);
const collection = new CategoryCollectionStub()
.withAction(new CategoryStub(0).withScript(expectedScript));
const sut = new CategoryCollectionState(collection);
// act
let actualScript: IScript;
sut.filter.filtered.on((result) => {
[actualScript] = result.scriptMatches;
});
sut.filter.setFilter(scriptNameFilter);
// assert
expect(expectedScript).to.equal(actualScript);
});
});
});