Skip to content

Commit 3b162c2

Browse files
Merge branch 'feature/tslint-to-eslint' into develop
2 parents 4931388 + bcba7dc commit 3b162c2

File tree

10 files changed

+664
-114
lines changed

10 files changed

+664
-114
lines changed

.eslintignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/coverage/
2+
/demo/demo.js
3+
/lib/

.eslintrc.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"parser": "@typescript-eslint/parser",
3+
"extends": [
4+
"airbnb-base",
5+
"plugin:jest/recommended",
6+
"plugin:@typescript-eslint/eslint-recommended",
7+
"plugin:@typescript-eslint/recommended",
8+
"prettier",
9+
"prettier/@typescript-eslint"
10+
],
11+
"parserOptions": {
12+
"ecmaVersion": 2018
13+
},
14+
"rules": {
15+
"import/prefer-default-export": "off"
16+
},
17+
"settings": {
18+
"import/parsers": {
19+
"@typescript-eslint/parser": [
20+
".ts"
21+
]
22+
},
23+
"import/resolver": {
24+
"typescript": {}
25+
}
26+
}
27+
}

package.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"build-demo": "webpack --config demo/webpack.config.js",
2121
"clean": "rimraf lib/*",
2222
"format": "prettier --write 'src/**'",
23-
"lint": "tsc; tslint -p ./",
23+
"lint": "tsc; eslint . --report-unused-disable-directives --ext .js,.ts",
2424
"precommit": "pretty-quick --staged",
2525
"test": "jest --coverage",
2626
"travisci": "npm run lint && npm run test"
@@ -50,14 +50,21 @@
5050
"@babel/preset-typescript": "^7.0.0-beta.54",
5151
"@types/es6-shim": "^0.31.37",
5252
"@types/jest": "^23.3.1",
53+
"@typescript-eslint/eslint-plugin": "^2.2.0",
54+
"@typescript-eslint/parser": "^2.2.0",
55+
"eslint": "6.1.0",
56+
"eslint-config-airbnb-base": "14.0.0",
57+
"eslint-config-prettier": "^6.3.0",
58+
"eslint-import-resolver-typescript": "^1.1.1",
59+
"eslint-plugin-import": "^2.18.2",
60+
"eslint-plugin-jest": "^22.17.0",
5361
"husky": "^0.14.3",
5462
"jest": "^23.4.1",
5563
"prettier": "^1.13.7",
5664
"pretty-quick": "^1.6.0",
5765
"rimraf": "^2.6.2",
5866
"ts-jest": "^23.0.1",
5967
"ts-loader": "^5.0.0",
60-
"tslint": "^5.11.0",
6168
"typescript": "^2.9.2",
6269
"webpack": "^4.17.2",
6370
"webpack-command": "^0.4.1"

src/demo.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function generatePattern(
2424
}
2525

2626
let clearSuccessIndicatorHandle: number;
27-
function displayPattern(pattern: string) {
27+
function displayPattern(pattern: string): void {
2828
$output.value = pattern;
2929

3030
// Temporarily style the output box as valid
@@ -37,7 +37,7 @@ function displayPattern(pattern: string) {
3737
);
3838
}
3939

40-
function onClickGenerate() {
40+
function onClickGenerate(): void {
4141
try {
4242
if (!$form.reportValidity()) {
4343
return;
@@ -66,7 +66,7 @@ document
6666
.querySelector('.js-generate')
6767
.addEventListener('click', onClickGenerate);
6868

69-
(() => {
69+
((): void => {
7070
const exampleInput =
7171
'Alabama, Alaska, Arizona, Arkansas, California, ' +
7272
'Colorado, Connecticut, Delaware, Florida, Georgia';

src/types/charTrie.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
1-
interface ICharTrieData {
2-
[prefix: string]: ICharTrieData;
1+
interface CharTrieData {
2+
[prefix: string]: CharTrieData;
33
}
44

55
export type Char = string;
6-
export interface ICharTrie extends Map<Char, ICharTrie> {
7-
[headChar: string]: any | ICharTrie;
8-
}
9-
10-
export class CharTrie extends Map<Char, CharTrie> implements ICharTrie {
11-
[headChar: string]: any | CharTrie;
126

13-
public static create(trieData: ICharTrieData): CharTrie {
7+
export class CharTrie extends Map<Char, CharTrie> {
8+
public static create(trieData: CharTrieData): CharTrie {
149
const trieDataPairs = Object.entries(trieData);
1510

1611
const trie = trieDataPairs.reduce(

src/utils/pattern.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ICharTrie } from '../types/charTrie';
1+
import { CharTrie } from '../types/charTrie';
22

33
/**
44
* Generate a regular expression pattern that captures the strings
@@ -7,7 +7,7 @@ import { ICharTrie } from '../types/charTrie';
77
* @param charTrie A character trie
88
* @returns A regular expression pattern
99
*/
10-
export function build(charTrie: ICharTrie): string {
10+
export function build(charTrie: CharTrie): string {
1111
const patternSegments = Array.from(
1212
[...charTrie],
1313
([head, suffixTrie]) => `${head}${build(suffixTrie)}`

src/utils/trie.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Char, ICharTrie } from '../types/charTrie';
1+
import { Char, CharTrie } from '../types/charTrie';
22

3-
const leafNode = new Map() as ICharTrie;
3+
const leafNode = new Map() as CharTrie;
44

55
function groupWordsByHeadChar(
66
words: string[],
@@ -30,13 +30,20 @@ function groupWordsByHeadChar(
3030
* @param tailGroup A character trie of suffixes to headChar
3131
* @returns A character trie with tailGroup branching from headChar
3232
*/
33-
function mergeGroups(headChar: Char, tailGroup: ICharTrie): ICharTrie {
33+
function mergeGroups(headChar: Char, tailGroup: CharTrie): CharTrie {
3434
if (tailGroup.size !== 1) {
35-
return new Map([[headChar, tailGroup]]) as ICharTrie;
35+
return new Map([[headChar, tailGroup]]) as CharTrie;
3636
}
3737

3838
const [onlyTail, onBranch] = tailGroup.entries().next().value;
39-
return new Map([[headChar + onlyTail, onBranch]]) as ICharTrie;
39+
return new Map([[headChar + onlyTail, onBranch]]) as CharTrie;
40+
}
41+
42+
/** @borrows buildUnique as build */
43+
export function build(words: string[]): CharTrie {
44+
const uniqueWords = [...new Set(words)];
45+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
46+
return buildUnique(uniqueWords);
4047
}
4148

4249
/**
@@ -45,7 +52,7 @@ function mergeGroups(headChar: Char, tailGroup: ICharTrie): ICharTrie {
4552
* @param words A list of words to parse
4653
* @returns A trie of words grouped by the initial characters they share
4754
*/
48-
function buildUnique(words: string[]): ICharTrie {
55+
function buildUnique(words: string[]): CharTrie {
4956
if (words.length === 0) {
5057
return leafNode;
5158
}
@@ -56,7 +63,7 @@ function buildUnique(words: string[]): ICharTrie {
5663
// End of the target word reached. Include an empty string to signify that
5764
// a word ends at this spot, and group any remaining words in the trie.
5865
const nonEmptyWords = words.filter(word => word !== '');
59-
return new Map([['', leafNode], ...build(nonEmptyWords)]) as ICharTrie;
66+
return new Map([['', leafNode], ...build(nonEmptyWords)]) as CharTrie;
6067
}
6168

6269
// Begin a new trie containing all words starting with the same letter as wordToMatch
@@ -68,11 +75,5 @@ function buildUnique(words: string[]): ICharTrie {
6875

6976
const groupWithChildren = mergeGroups(charToMatch, tailsMatchedGrouped);
7077

71-
return new Map([...groupWithChildren, ...build(wordsMissed)]) as ICharTrie;
72-
}
73-
74-
/** @borrows buildUnique as build */
75-
export function build(words: string[]): ICharTrie {
76-
const uniqueWords = [...new Set(words)];
77-
return buildUnique(uniqueWords);
78+
return new Map([...groupWithChildren, ...build(wordsMissed)]) as CharTrie;
7879
}

src/utils/wordList.spec.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { parseString, WhitespaceHandling } from './wordList';
22

3-
interface ITestCase {
3+
interface TestCase {
44
delimiter: string;
55
inputString: string;
66
}
@@ -9,7 +9,7 @@ const { Preserve, TrimLeadingAndTrailing } = WhitespaceHandling;
99

1010
describe('parseString', () => {
1111
it('returns an empty array when input string is empty', () => {
12-
function testInput(input: string) {
12+
function testInput(input: string): void {
1313
const wordList = parseString(input, ',', Preserve);
1414
expect(wordList).toEqual([]);
1515
}
@@ -18,7 +18,7 @@ describe('parseString', () => {
1818
});
1919

2020
it('returns entire input string in array when delimiter is empty', () => {
21-
function testDelimiter(delimiter: string) {
21+
function testDelimiter(delimiter: string): void {
2222
const wordList = parseString(' some input string ', delimiter, Preserve);
2323
expect(wordList).toEqual([' some input string ']);
2424
}
@@ -27,7 +27,7 @@ describe('parseString', () => {
2727
});
2828

2929
it('returns entire input string in array when delimiter is not present in input string', () => {
30-
function testDelimiter(delimiter: string) {
30+
function testDelimiter(delimiter: string): void {
3131
const wordList = parseString(' some input string ', delimiter, Preserve);
3232
expect(wordList).toEqual([' some input string ']);
3333
}
@@ -37,13 +37,13 @@ describe('parseString', () => {
3737

3838
it('splits input string by delimiter', () => {
3939
const expectedResult = ['foo', 'Bar', ' b@z '];
40-
const testCases: ITestCase[] = [
40+
const testCases: TestCase[] = [
4141
{ delimiter: ',', inputString: 'foo,Bar, b@z ' },
4242
{ delimiter: '\t', inputString: 'foo Bar b@z ' },
4343
{ delimiter: 'aaa', inputString: 'fooaaaBaraaa b@z ' },
4444
];
4545

46-
function testSplit({ delimiter, inputString }: ITestCase) {
46+
function testSplit({ delimiter, inputString }: TestCase): void {
4747
const wordList = parseString(inputString, delimiter, Preserve);
4848
expect(wordList).toEqual(expectedResult);
4949
}
@@ -53,12 +53,12 @@ describe('parseString', () => {
5353

5454
it('splits input string by whitespace delimiter', () => {
5555
const expectedResult = ['foo', 'Bar', 'b@z', ''];
56-
const testCases: ITestCase[] = [
56+
const testCases: TestCase[] = [
5757
{ delimiter: ' ', inputString: 'foo Bar b@z ' },
5858
{ delimiter: ' ', inputString: 'foo Bar b@z ' },
5959
];
6060

61-
function testSplit({ delimiter, inputString }: ITestCase) {
61+
function testSplit({ delimiter, inputString }: TestCase): void {
6262
const wordList = parseString(inputString, delimiter, Preserve);
6363
expect(wordList).toEqual(expectedResult);
6464
}

tslint.json

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)