Skip to content

Commit 258a0f5

Browse files
committed
Add eslint
1 parent 5b0f799 commit 258a0f5

File tree

14 files changed

+1366
-276
lines changed

14 files changed

+1366
-276
lines changed

.eslintignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules/
2+
build/
3+
coverage/

.eslintrc.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
const prettierConfig = require('./.prettierrc');
2+
3+
module.exports = {
4+
parser: '@typescript-eslint/parser',
5+
plugins: ['@typescript-eslint'],
6+
extends: [
7+
'@react-native-community',
8+
'eslint:recommended',
9+
'plugin:@typescript-eslint/eslint-recommended',
10+
'plugin:@typescript-eslint/recommended',
11+
],
12+
env: {
13+
node: true,
14+
},
15+
settings: {
16+
react: {
17+
version: 'latest',
18+
},
19+
},
20+
overrides: [
21+
{
22+
files: [
23+
'**/__mocks__/**',
24+
'**/__fixtures__/**',
25+
'**/__e2e__/**',
26+
'jest/**',
27+
],
28+
env: {
29+
jest: true,
30+
},
31+
},
32+
{
33+
files: ['*.ts', '**/*.ts'],
34+
rules: {
35+
'prettier/prettier': [2, {prettierConfig, parser: 'typescript'}],
36+
},
37+
},
38+
],
39+
};

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ node_modules
22
.DS_Store
33
.vscode
44
build/
5+
coverage/
56
*.tsbuildinfo
67
yarn-error.log

definitions/xcode/index.d.ts

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

definitions/xcode/lib/index.d.ts

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

jest.config.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const common = {testEnvironment: 'node'};
2+
3+
module.exports = {
4+
projects: [
5+
{
6+
...common,
7+
displayName: 'unit',
8+
// setupFiles: ['<rootDir>/jest/setupUnitTests.js'],
9+
testMatch: ['<rootDir>/**/__tests__/*{.,-}test.[jt]s'],
10+
},
11+
],
12+
collectCoverageFrom: [
13+
'src/**/*.ts',
14+
'!**/__mocks__/**',
15+
'!**/__tests__/**',
16+
'!**/build/**',
17+
],
18+
};

package.json

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
"version": "0.1.0",
44
"description": "React Native CLI Plugin for Benchmark Regression",
55
"scripts": {
6-
"build": "yarn tsc"
6+
"build": "yarn tsc",
7+
"lint": "eslint --ext .js,.ts . --cache --report-unused-disable-directives",
8+
"test": "jest",
9+
"test:ci:unit": "jest --ci --coverage"
710
},
811
"main": "build/index.js",
912
"files": [
@@ -13,29 +16,38 @@
1316
"repository": "https://github.com/Kudo/react-native-cli-plugin-benchmark",
1417
"license": "MIT",
1518
"devDependencies": {
19+
"@babel/core": "^7.8.6",
1620
"@babel/preset-env": "^7.8.4",
1721
"@babel/preset-typescript": "^7.8.3",
18-
"@react-native-community/cli-platform-android": "^4.0.1",
19-
"@react-native-community/cli-platform-ios": "^4.0.1",
22+
"@react-native-community/cli-platform-android": "^3.1.4",
23+
"@react-native-community/cli-platform-ios": "^3.2.0",
24+
"@react-native-community/cli-tools": "^3.0.0",
2025
"@react-native-community/cli-types": "^3.0.0",
26+
"@react-native-community/eslint-config": "^0.0.7",
2127
"@types/glob": "^7.1.1",
2228
"@types/graceful-fs": "^4.1.3",
2329
"@types/jest": "^25.1.3",
2430
"@types/lodash": "^4.14.149",
2531
"@types/node": "^13.7.1",
2632
"@types/node-fetch": "^2.5.4",
33+
"@typescript-eslint/eslint-plugin": "^2.21.0",
34+
"@typescript-eslint/parser": "^2.21.0",
35+
"eslint": "^6.8.0",
36+
"eslint-import-resolver-alias": "^1.1.2",
37+
"eslint-import-resolver-typescript": "^2.0.0",
38+
"eslint-plugin-import": "^2.20.1",
39+
"eslint-plugin-prettier": "^3.1.2",
2740
"jest": "^25.1.0",
2841
"prettier": "^1.19.1",
2942
"typescript": "^3.7.5"
3043
},
3144
"peerDependencies": {
32-
"@react-native-community/cli": "^3.1.0"
45+
"@react-native-community/cli": ">= 3.0.0"
3346
},
3447
"dependencies": {
3548
"execa": "^4.0.0",
3649
"glob": "^7.1.6",
3750
"graceful-fs": "^4.2.3",
38-
"lodash": "^4.17.15",
39-
"xcode": "^2.1.0"
51+
"lodash": "^4.17.15"
4052
}
4153
}

src/commands/common/ObjcPatcher.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,24 @@ export default class ObjcPatcher {
1717
return this._content.indexOf(this._patchSig) >= 0;
1818
}
1919

20-
addImport(file: string) {
20+
addImport(file: string): ObjcPatcher {
2121
const lastImportBegin = this._content.lastIndexOf('\n#import');
22-
let lastImportEnd = this._content.indexOf('\n', lastImportBegin + 1);
22+
const lastImportEnd = this._content.indexOf('\n', lastImportBegin + 1);
2323
const headPart = this._content.substring(0, lastImportEnd);
2424
const tailPart = this._content.substring(lastImportEnd);
2525
this._content = headPart + `\n#import ${file}` + tailPart;
2626
return this;
2727
}
2828

29-
addFunction(code: string) {
29+
addFunction(code: string): ObjcPatcher {
3030
const lastImplEnd = this._content.lastIndexOf('\n@end');
3131
const headPart = this._content.substring(0, lastImplEnd);
3232
const tailPart = this._content.substring(lastImplEnd);
3333
this._content = headPart + `\n${code}` + tailPart;
3434
return this;
3535
}
3636

37-
replace(searchValue: string | RegExp, replaceValue: string) {
37+
replace(searchValue: string | RegExp, replaceValue: string): ObjcPatcher {
3838
this._content = this._content.replace(searchValue, replaceValue);
3939
return this;
4040
}
@@ -44,7 +44,7 @@ export default class ObjcPatcher {
4444
fs.writeFileSync(toFile, this._content);
4545
}
4646

47-
_addPatchSigIfNeeded() {
47+
_addPatchSigIfNeeded(): ObjcPatcher {
4848
if (this.isPatched()) {
4949
return this;
5050
}

0 commit comments

Comments
 (0)