Skip to content

Commit 207ce3f

Browse files
authored
chore: improve prettier config (#231)
* fix: `typeorm` missing in `bun.lockb` * chore: add npm `prepare` script * Update bun.lockb * Update bun.lockb * chore: build package on `prepublishOnly` * chore: add `typeorm` dependency top-level * fix: eslint jest error in CI * chore: use prettier in VS Code * fix: typescript-eslint setup * chore: extract prettier config * chore: update prettier config * chore: move prettier config to top level * chore: run prettier * chore: remove prettier from eslitn * fix: eslint errors
1 parent 8af36ea commit 207ce3f

27 files changed

+172
-145
lines changed

.prettierignore

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
*.html
2+
*.yml
3+
*.yaml
4+
*.css
5+
*.scss
6+
*.md
7+
*.markdown
8+
9+
package/lib
10+
11+
.well-known
12+
android
13+
ios
14+
vendor
15+
package.json
16+
package-lock.json
17+
18+
# The GH actions don't seem to compile and verify themselves well when Prettier is applied to them
19+
.github/actions/javascript/**/index.js
20+

.prettierrc.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {
2+
quoteProps: 'consistent',
3+
singleQuote: true,
4+
tabWidth: 2,
5+
trailingComma: 'all',
6+
useTabs: false,
7+
singleAttributePerLine: true,
8+
semi: false,
9+
}

.watchmanconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{}
1+
{}

config/.eslintrc.js

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
module.exports = {
22
root: true,
33
ignorePatterns: [
4-
"**/node_modules",
5-
"**/lib",
6-
"**/.eslintrc.js",
7-
"**/.prettierrc.js",
8-
"**/jest.config.js",
9-
"**/babel.config.js",
10-
"**/metro.config.js",
11-
"**/react-native.config.js",
12-
"**/tsconfig.json"
4+
'**/node_modules',
5+
'**/lib',
6+
'**/.eslintrc.js',
7+
'**/.prettierrc.js',
8+
'**/jest.config.js',
9+
'**/babel.config.js',
10+
'**/metro.config.js',
11+
'**/react-native.config.js',
12+
'**/tsconfig.json',
1313
],
14-
extends: ['@react-native','plugin:prettier/recommended'],
15-
plugins: ['@typescript-eslint', 'prettier'],
14+
extends: [
15+
'@react-native',
16+
'plugin:prettier/recommended',
17+
'plugin:@typescript-eslint/recommended',
18+
],
19+
plugins: ['@typescript-eslint', 'jest'],
1620
parser: '@typescript-eslint/parser',
1721
parserOptions: {
1822
project: true,
@@ -23,17 +27,4 @@ module.exports = {
2327
ecmaVersion: 2018,
2428
sourceType: 'module',
2529
},
26-
rules: {
27-
'prettier/prettier': [
28-
'warn',
29-
{
30-
quoteProps: 'consistent',
31-
singleQuote: true,
32-
tabWidth: 2,
33-
trailingComma: 'es5',
34-
useTabs: false,
35-
semi: false,
36-
},
37-
],
38-
},
3930
}

example/.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ module.exports = {
55
project: true,
66
tsconfigRootDir: __dirname,
77
},
8-
};
8+
}

example/.watchmanconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{}
1+
{}

example/babel.config.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const path = require('path');
2-
const pak = require('../package/package.json');
1+
const path = require('path')
2+
const pak = require('../package/package.json')
33

44
module.exports = {
55
presets: ['module:@react-native/babel-preset'],
@@ -10,12 +10,12 @@ module.exports = {
1010
extensions: ['.tsx', '.ts', '.js', '.json'],
1111
alias: {
1212
[pak.name]: path.join(__dirname, '../package', pak.source),
13-
stream: 'stream-browserify',
13+
'stream': 'stream-browserify',
1414
'react-native-sqlite-storage': 'react-native-nitro-sqlite',
1515
},
1616
},
1717
],
1818
'babel-plugin-transform-typescript-metadata',
19-
['@babel/plugin-proposal-decorators', {legacy: true}],
19+
['@babel/plugin-proposal-decorators', { legacy: true }],
2020
],
21-
};
21+
}

example/metro.config.js

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
1-
const fs = require('fs');
2-
const path = require('path');
3-
const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');
4-
const exclusionList = require('metro-config/src/defaults/exclusionList');
5-
const escape = require('escape-string-regexp');
1+
const fs = require('fs')
2+
const path = require('path')
3+
const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config')
4+
const exclusionList = require('metro-config/src/defaults/exclusionList')
5+
const escape = require('escape-string-regexp')
66

7-
const root = path.resolve(__dirname, '..');
8-
const rootNodeModulesPath = path.join(root, 'node_modules');
9-
const exampleNodeModulesPath = path.join(__dirname, 'node_modules');
7+
const root = path.resolve(__dirname, '..')
8+
const rootNodeModulesPath = path.join(root, 'node_modules')
9+
const exampleNodeModulesPath = path.join(__dirname, 'node_modules')
1010

1111
function getPackageNames(nodeModulesPath) {
1212
if (!fs.existsSync(nodeModulesPath)) {
13-
return [];
13+
return []
1414
}
1515

16-
const allFiles = fs.readdirSync(nodeModulesPath);
16+
const allFiles = fs.readdirSync(nodeModulesPath)
1717

1818
// Filter out only directories (package names)
19-
const packageNames = allFiles.filter(file => {
20-
const filePath = path.join(nodeModulesPath, file);
21-
return fs.statSync(filePath).isDirectory();
22-
});
19+
const packageNames = allFiles.filter((file) => {
20+
const filePath = path.join(nodeModulesPath, file)
21+
return fs.statSync(filePath).isDirectory()
22+
})
2323

2424
// Handle scoped packages (e.g., @scope/package)
2525
const scopedPackages = packageNames
26-
.filter(pkg => pkg.startsWith('@'))
27-
.flatMap(scope => {
28-
const scopePath = path.join(nodeModulesPath, scope);
29-
const scopedFiles = fs.readdirSync(scopePath);
30-
return scopedFiles.map(scopedFile => `${scope}/${scopedFile}`);
31-
});
26+
.filter((pkg) => pkg.startsWith('@'))
27+
.flatMap((scope) => {
28+
const scopePath = path.join(nodeModulesPath, scope)
29+
const scopedFiles = fs.readdirSync(scopePath)
30+
return scopedFiles.map((scopedFile) => `${scope}/${scopedFile}`)
31+
})
3232

3333
// Return both regular and scoped package names
3434
return packageNames
35-
.filter(pkg => !pkg.startsWith('@'))
36-
.concat(scopedPackages);
35+
.filter((pkg) => !pkg.startsWith('@'))
36+
.concat(scopedPackages)
3737
}
3838

39-
const exampleNodeModules = getPackageNames(exampleNodeModulesPath);
39+
const exampleNodeModules = getPackageNames(exampleNodeModulesPath)
4040

4141
const config = {
4242
projectRoot: __dirname,
@@ -48,7 +48,8 @@ const config = {
4848
unstable_enableSymlinks: true,
4949
blockList: exclusionList(
5050
exampleNodeModules.map(
51-
m => new RegExp(`^${escape(path.join(rootNodeModulesPath, m))}\\/.*$`),
51+
(m) =>
52+
new RegExp(`^${escape(path.join(rootNodeModulesPath, m))}\\/.*$`),
5253
),
5354
),
5455

@@ -70,6 +71,6 @@ const config = {
7071
},
7172
}),
7273
},
73-
};
74+
}
7475

75-
module.exports = mergeConfig(getDefaultConfig(__dirname), config);
76+
module.exports = mergeConfig(getDefaultConfig(__dirname), config)

example/react-native.config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
const path = require('path');
2-
const pak = require('../package/package.json');
1+
const path = require('path')
2+
const pak = require('../package/package.json')
33

44
module.exports = {
55
dependencies: {
66
[pak.name]: {
77
root: path.join(__dirname, '../package'),
88
},
99
},
10-
};
10+
}

example/src/App.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,18 @@ export default function App() {
1111
return (
1212
<NavigationContainer>
1313
<RootStack.Navigator initialRouteName="NitroSQLite Example">
14-
<RootStack.Screen name="NitroSQLite Example" component={HomeScreen} />
15-
<RootStack.Screen name="Unit Tests" component={UnitTestScreen} />
16-
<RootStack.Screen name="Benchmarks" component={BenchmarkScreen} />
14+
<RootStack.Screen
15+
name="NitroSQLite Example"
16+
component={HomeScreen}
17+
/>
18+
<RootStack.Screen
19+
name="Unit Tests"
20+
component={UnitTestScreen}
21+
/>
22+
<RootStack.Screen
23+
name="Benchmarks"
24+
component={BenchmarkScreen}
25+
/>
1726
</RootStack.Navigator>
1827

1928
<StatusBar style="auto" />

0 commit comments

Comments
 (0)