Skip to content

Commit ad32031

Browse files
committed
eslint追加
1 parent 7a27230 commit ad32031

File tree

10 files changed

+708
-71
lines changed

10 files changed

+708
-71
lines changed

.eslintrc.json

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"env": {
3+
"commonjs": true,
4+
"es2020": true
5+
},
6+
"extends": [
7+
"eslint:recommended",
8+
"plugin:@typescript-eslint/eslint-recommended",
9+
"plugin:@typescript-eslint/recommended",
10+
"plugin:@typescript-eslint/recommended-requiring-type-checking",
11+
"prettier"
12+
],
13+
"parser": "@typescript-eslint/parser",
14+
"parserOptions": {
15+
"sourceType": "module",
16+
"project":"./tsconfig.json"
17+
},
18+
"plugins": [
19+
"@typescript-eslint",
20+
"prettier"
21+
],
22+
"rules": {
23+
"prettier/prettier": [
24+
"error",
25+
{
26+
"printWidth": 120,
27+
"tabWidth": 2,
28+
"useTabs": false,
29+
"semi": true,
30+
"singleQuote": true,
31+
"trailingComma": "all",
32+
"bracketSpacing": true,
33+
"arrowParens": "always"
34+
}
35+
],
36+
"eqeqeq": "error",
37+
"prefer-template": "error",
38+
"complexity": ["warn", 10],
39+
"max-depth": ["warn", 3],
40+
"max-statements": ["warn", 30],
41+
"max-lines": ["warn"],
42+
"no-console": "warn",
43+
"no-debugger": "error",
44+
"no-warning-comments": ["warn", { "terms": ["todo", "fixme", "hack"], "location": "anywhere" }]
45+
}
46+
}

.vscode/extensions.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"recommendations": [
3+
"dbaeumer.vscode-eslint"
4+
]
5+
}

.vscode/settings.json

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
{
2-
"git.ignoreLimitWarning": true,
3-
"tslint.alwaysShowRuleFailuresAsWarnings": true,
4-
"tslint.configFile": "tslint.json",
5-
"[markdown]": {
6-
"files.trimTrailingWhitespace": false
7-
},
8-
"editor.tabSize": 2,
9-
"files.insertFinalNewline": true,
10-
}
1+
{
2+
"git.ignoreLimitWarning": true,
3+
"[markdown]": {
4+
"files.trimTrailingWhitespace": false
5+
},
6+
"editor.tabSize": 2,
7+
"files.insertFinalNewline": true,
8+
"files.eol": "\n",
9+
"[typescript]": {
10+
"editor.formatOnSave": false,
11+
"editor.codeActionsOnSave": {
12+
"source.fixAll.eslint": true
13+
}
14+
},
15+
}

package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@
77
"dependencies": {},
88
"devDependencies": {
99
"@types/jest": "^27.0.3",
10+
"@typescript-eslint/eslint-plugin": "^5.6.0",
11+
"@typescript-eslint/parser": "^5.6.0",
12+
"eslint": "^8.4.1",
13+
"eslint-config-prettier": "^8.3.0",
14+
"eslint-plugin-prettier": "^4.0.0",
1015
"jest": "^27.4.4",
16+
"prettier": "^2.5.1",
1117
"ts-jest": "^27.1.1",
1218
"typescript": "^4.5.3"
1319
},
@@ -16,7 +22,8 @@
1622
"prepare": "npm run build",
1723
"test": "jest",
1824
"test:w": "jest --watch",
19-
"test:wa": "jest --watchAll"
25+
"test:wa": "jest --watchAll",
26+
"lint": "eslint src --ext .ts"
2027
},
2128
"main": "dist/index.js",
2229
"types": "dist/index.d.ts",

src/ext/array/alias-linq.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,28 +59,28 @@ declare global {
5959
}
6060
}
6161

62-
Array.prototype.select = function<T, U>(callbackfn: (value: T, index: number, array: T[]) => U): U[] {
62+
Array.prototype.select = function <T, U>(callbackfn: (value: T, index: number, array: T[]) => U): U[] {
6363
const items = this as T[];
6464
return items.map(callbackfn);
6565
};
6666

67-
Array.prototype.where = function<T>(callbackfn: (value: T, index: number, array: T[]) => any): T[] {
67+
Array.prototype.where = function <T>(callbackfn: (value: T, index: number, array: T[]) => any): T[] {
6868
const items = this as T[];
6969
return items.filter(callbackfn);
7070
};
7171

72-
Array.prototype.all = function<T>(callbackfn: (value: T, index: number, array: T[]) => boolean): boolean {
72+
Array.prototype.all = function <T>(callbackfn: (value: T, index: number, array: T[]) => boolean): boolean {
7373
const items = this as T[];
7474
if (!Array.isArray(items) || items.length === 0) return false;
7575
return items.every(callbackfn);
7676
};
7777

78-
Array.prototype.skip = function<T>(count: number): T[] {
78+
Array.prototype.skip = function <T>(count: number): T[] {
7979
const items = this as T[];
8080
return items.slice(count);
8181
};
8282

83-
Array.prototype.take = function<T>(count: number): T[] {
83+
Array.prototype.take = function <T>(count: number): T[] {
8484
const items = this as T[];
8585
return items.slice(0, count);
8686
};

src/ext/array/where-non-nil.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
export {};
2-
3-
declare global {
4-
interface Array<T> {
5-
/**
6-
* [拡張メソッド]
7-
* null, undefinedを除外した配列を取得します。
8-
* @return 抽出後の配列
9-
*/
10-
whereNonNil(): NonNullable<T>[];
11-
}
12-
}
13-
14-
Array.prototype.whereNonNil = function<T>(): NonNullable<T>[] {
15-
const items = this as T[];
16-
return items.filter((item): item is NonNullable<T> => item !== null && item !== undefined);
17-
};
1+
export {};
2+
3+
declare global {
4+
interface Array<T> {
5+
/**
6+
* [拡張メソッド]
7+
* null, undefinedを除外した配列を取得します。
8+
* @return 抽出後の配列
9+
*/
10+
whereNonNil(): NonNullable<T>[];
11+
}
12+
}
13+
14+
Array.prototype.whereNonNil = function <T>(): NonNullable<T>[] {
15+
const items = this as T[];
16+
return items.filter((item): item is NonNullable<T> => item !== null && item !== undefined);
17+
};

src/ext/object/equal-to.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
export {};
2-
3-
declare global {
4-
interface Object {
5-
/**
6-
* [拡張メソッド]
7-
* オブジェクトの内容が同じ場合、true
8-
* @param target 比較先のオブジェクト
9-
* @return オブジェクトの内容が同じ場合、true
10-
*/
11-
equalTo(target: object): boolean;
12-
}
13-
}
14-
15-
Object.prototype.equalTo = function(target: object) {
16-
if (target === null || target === undefined) return false;
17-
// JSON文字列化して比較
18-
const sourceJson = JSON.stringify(this);
19-
const targetJson = JSON.stringify(target);
20-
return sourceJson === targetJson;
21-
};
1+
export {};
2+
3+
declare global {
4+
interface Object {
5+
/**
6+
* [拡張メソッド]
7+
* オブジェクトの内容が同じ場合、true
8+
* @param target 比較先のオブジェクト
9+
* @return オブジェクトの内容が同じ場合、true
10+
*/
11+
equalTo(target: object): boolean;
12+
}
13+
}
14+
15+
Object.prototype.equalTo = function (target: object) {
16+
if (target === null || target === undefined) return false;
17+
// JSON文字列化して比較
18+
const sourceJson = JSON.stringify(this);
19+
const targetJson = JSON.stringify(target);
20+
return sourceJson === targetJson;
21+
};

test/any-test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ describe('Array.any', () => {
66
const items = [1, 2, 3];
77

88
// exercise
9-
const actual = items.any(value => value === 2);
9+
const actual = items.any((value) => value === 2);
1010

1111
// verify
1212
expect(actual).toBeTruthy();
@@ -17,7 +17,7 @@ describe('Array.any', () => {
1717
const items = [1, 2, 3];
1818

1919
// exercise
20-
const actual = items.any(value => value === 4);
20+
const actual = items.any((value) => value === 4);
2121

2222
// verify
2323
expect(actual).toBeFalsy();

test/distinct-test.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,13 @@ describe('Array.distinctBy', () => {
3434
];
3535

3636
// exercise
37-
const actual = items.distinctBy(item => item.name);
37+
const actual = items.distinctBy((item) => item.name);
3838

3939
// verify
40-
expect(actual).toEqual([{ id: 1, name: 'Alex' }, { id: 2, name: 'Bob' } ]);
40+
expect(actual).toEqual([
41+
{ id: 1, name: 'Alex' },
42+
{ id: 2, name: 'Bob' },
43+
]);
4144
});
4245

4346
it('number', () => {
@@ -49,18 +52,21 @@ describe('Array.distinctBy', () => {
4952
];
5053

5154
// exercise
52-
const actual = items.distinctBy(item => item.id);
55+
const actual = items.distinctBy((item) => item.id);
5356

5457
// verify
55-
expect(actual).toEqual([{ id: 1, name: 'Alex' }, { id: 2, name: 'Alex' } ]);
58+
expect(actual).toEqual([
59+
{ id: 1, name: 'Alex' },
60+
{ id: 2, name: 'Alex' },
61+
]);
5662
});
5763

5864
it('Array.length = 0', () => {
5965
// setup
6066
const items = [] as number[];
6167

6268
// exercise
63-
const actual = items.distinctBy(item => item);
69+
const actual = items.distinctBy((item) => item);
6470

6571
// verify
6672
expect(actual).toEqual([]);

0 commit comments

Comments
 (0)