Skip to content

Commit 02cec5e

Browse files
committed
chore: setup eslint and prettier
1 parent 43cc6c2 commit 02cec5e

File tree

15 files changed

+905
-85
lines changed

15 files changed

+905
-85
lines changed

.babelrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
}
77
}],
88
"@babel/preset-typescript"
9-
]
9+
],
10+
"plugins": ["@babel/plugin-proposal-optional-chaining"]
1011
}

.eslintignore

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

.eslintrc.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "satya164",
3+
"env": { "node": true }
4+
}

bin/bob.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
#!/usr/bin/env node
22

3+
// eslint-disable-next-line import/no-commonjs
34
require('../lib/cli');

commitlint.config.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* eslint-disable import/no-commonjs */
2-
31
module.exports = {
42
extends: ['@commitlint/config-conventional'],
53
};

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"registry": "https://registry.npmjs.org/"
1919
},
2020
"scripts": {
21+
"lint": "eslint --ext '.js,.ts,.tsx' .",
2122
"typescript": "tsc --noEmit",
2223
"build": "babel --extensions .ts,.tsx src --out-dir lib --ignore '**/__tests__/**' --source-maps --delete-dir-on-start",
2324
"watch": "yarn build --watch",
@@ -41,6 +42,7 @@
4142
},
4243
"devDependencies": {
4344
"@babel/cli": "^7.7.7",
45+
"@babel/plugin-proposal-optional-chaining": "^7.7.5",
4446
"@babel/preset-env": "^7.7.7",
4547
"@babel/preset-typescript": "^7.7.7",
4648
"@commitlint/config-conventional": "^8.2.0",
@@ -53,6 +55,8 @@
5355
"@types/inquirer": "^6.5.0",
5456
"@types/yargs": "^13.0.3",
5557
"commitlint": "^8.2.0",
58+
"eslint": "^6.7.2",
59+
"eslint-config-satya164": "^3.1.5",
5660
"husky": "^3.1.0",
5761
"prettier": "^1.19.1",
5862
"release-it": "^12.4.3",
@@ -61,7 +65,7 @@
6165
"husky": {
6266
"hooks": {
6367
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
64-
"pre-commit": "yarn typescript"
68+
"pre-commit": "yarn lint && yarn typescript"
6569
}
6670
}
6771
}

src/cli.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@ import buildModule from './targets/module';
1212
import buildTypescript from './targets/typescript';
1313
import { Options } from './types';
1414

15+
// eslint-disable-next-line import/no-commonjs
1516
const { name } = require('../package.json');
17+
1618
const root = process.cwd();
1719
const explorer = cosmiconfigSync(name);
1820

1921
const FLOW_PRGAMA_REGEX = /\*?\s*@(flow)\b/m;
2022

23+
// eslint-disable-next-line babel/no-unused-expressions
2124
yargs
2225
.command('init', 'configure the package to use bob', {}, async () => {
2326
const pak = path.join(root, 'package.json');
@@ -131,9 +134,7 @@ yargs
131134
const { replace } = await inquirer.prompt({
132135
type: 'confirm',
133136
name: 'replace',
134-
message: `Your package.json has the '${key}' field set to '${
135-
pkg[key]
136-
}'. Do you want to replace it with '${entry}'?`,
137+
message: `Your package.json has the '${key}' field set to '${pkg[key]}'. Do you want to replace it with '${entry}'?`,
137138
default: true,
138139
});
139140

@@ -149,9 +150,7 @@ yargs
149150
const { replace } = await inquirer.prompt({
150151
type: 'confirm',
151152
name: 'replace',
152-
message: `Your package.json has the 'scripts.prepare' field set to '${
153-
pkg.scripts.prepare
154-
}'. Do you want to replace it with '${prepare}'?`,
153+
message: `Your package.json has the 'scripts.prepare' field set to '${pkg.scripts.prepare}'. Do you want to replace it with '${prepare}'?`,
155154
default: true,
156155
});
157156

@@ -233,11 +232,9 @@ yargs
233232
.command('build', 'build files for publishing', {}, async argv => {
234233
const result = explorer.search();
235234

236-
if (!(result && result.config)) {
235+
if (!result?.config) {
237236
logger.exit(
238-
`No configuration found. Run '${
239-
argv.$0
240-
} init' to create one automatically.`
237+
`No configuration found. Run '${argv.$0} init' to create one automatically.`
241238
);
242239
}
243240

src/targets/aar.ts

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ import { Input } from '../types';
77
import jetifier from '../utils/jetifier';
88

99
type TargetOptions = {
10-
androidPath: string,
10+
androidPath: string;
1111
androidBundleName: string;
12-
reverseJetify: boolean
12+
reverseJetify: boolean;
1313
};
1414

1515
const defaultOptions: TargetOptions = {
16-
androidPath: "android",
17-
androidBundleName: "android.aar",
18-
reverseJetify: false
16+
androidPath: 'android',
17+
androidBundleName: 'android.aar',
18+
reverseJetify: false,
1919
};
2020

2121
type Options = Input & {
@@ -24,7 +24,10 @@ type Options = Input & {
2424

2525
async function createGradleFile(file: string) {
2626
await fs.createFile(file);
27-
await fs.writeFile(file, 'configurations.maybeCreate("default")\nartifacts.add("default", file(\'android.aar\'))')
27+
await fs.writeFile(
28+
file,
29+
'configurations.maybeCreate("default")\nartifacts.add("default", file(\'android.aar\'))'
30+
);
2831
}
2932

3033
export default async function build({
@@ -35,7 +38,7 @@ export default async function build({
3538
}: Options) {
3639
const targetOptions = {
3740
...defaultOptions,
38-
...options
41+
...options,
3942
};
4043

4144
report.info(
@@ -44,18 +47,32 @@ export default async function build({
4447

4548
await del([output]);
4649

47-
await androidAssemble({ root, androidPath: targetOptions.androidPath, report });
50+
await androidAssemble({
51+
root,
52+
androidPath: targetOptions.androidPath,
53+
report,
54+
});
4855

4956
report.info(
50-
`Creating new output directory at ${chalk.blue(path.relative(root, output))}`
57+
`Creating new output directory at ${chalk.blue(
58+
path.relative(root, output)
59+
)}`
5160
);
5261
await fs.mkdir(output);
5362

54-
const sourceAar = path.join(targetOptions.androidPath, 'build', 'outputs', 'aar', targetOptions.androidBundleName);
63+
const sourceAar = path.join(
64+
targetOptions.androidPath,
65+
'build',
66+
'outputs',
67+
'aar',
68+
targetOptions.androidBundleName
69+
);
5570
const targetAar = path.join(output, targetOptions.androidBundleName);
5671

5772
report.info(
58-
`Copying AAR from ${chalk.blue(path.relative(root, sourceAar))} to ${chalk.blue(path.relative(root, targetAar))}`
73+
`Copying AAR from ${chalk.blue(
74+
path.relative(root, sourceAar)
75+
)} to ${chalk.blue(path.relative(root, targetAar))}`
5976
);
6077
await fs.copyFile(sourceAar, targetAar);
6178

@@ -68,31 +85,38 @@ export default async function build({
6885
if (targetOptions.reverseJetify) {
6986
const supportOutputPath = path.join(output, 'support');
7087
report.info(
71-
`Creating new support output directory at ${chalk.blue(path.relative(root, supportOutputPath))}`
88+
`Creating new support output directory at ${chalk.blue(
89+
path.relative(root, supportOutputPath)
90+
)}`
7291
);
7392
await fs.mkdir(supportOutputPath);
7493

75-
const supportAar = path.join(supportOutputPath, targetOptions.androidBundleName);
94+
const supportAar = path.join(
95+
supportOutputPath,
96+
targetOptions.androidBundleName
97+
);
7698
report.info(
77-
`Using Jetifier to convert AAR from AndroidX to Support AAR at ${chalk.blue(path.relative(root, supportAar))}`
99+
`Using Jetifier to convert AAR from AndroidX to Support AAR at ${chalk.blue(
100+
path.relative(root, supportAar)
101+
)}`
78102
);
79103

80104
await jetifier({
81105
root,
82106
report,
83107
input: targetAar,
84108
output: supportAar,
85-
reverse: true
109+
reverse: true,
86110
});
87111

88112
const supportGradleFile = path.join(supportOutputPath, 'build.gradle');
89113
report.info(
90-
`Creating Support AAR Gradle file at ${chalk.blue(path.relative(root, supportGradleFile))}`
114+
`Creating Support AAR Gradle file at ${chalk.blue(
115+
path.relative(root, supportGradleFile)
116+
)}`
91117
);
92118
await createGradleFile(supportGradleFile);
93119
}
94120

95-
report.success(
96-
`Wrote files to ${chalk.blue(path.relative(root, output))}`
97-
);
121+
report.success(`Wrote files to ${chalk.blue(path.relative(root, output))}`);
98122
}

src/targets/commonjs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default async function build({
2828
options: {
2929
presets: [[require.resolve('metro-react-native-babel-preset')]],
3030
},
31-
flow: options && options.flow ? true : false,
31+
flow: options?.flow ? true : false,
3232
report,
3333
});
3434
}

src/targets/module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export default async function build({
3333
],
3434
],
3535
},
36-
flow: options && options.flow ? true : false,
36+
flow: options?.flow ? true : false,
3737
report,
3838
});
3939
}

0 commit comments

Comments
 (0)