Skip to content

Commit 6dcc759

Browse files
Add pre-commit hook and linters for Android and iOS code (#2114)
## Description This PR: - Removes unnecessary `.gitignore`, `build.gradle` and `proguard-rules.pro` files from the `lib/` directory. I believe those were leftovers from when Gesture Handler could be used as a native Android library - Adds Gradle wrapper in the `android/` directory - Adds Spotless for linting the Android code, similarly to how it's done in Screens - Adds `.clang-format` for linting the iOS code, the config is the same as in Screens and Reanimated - Adds a pre-commit hook similarly to how it's implemented in Screens - Adds workflow that lints Android code - Formats Android code so that it passes `spotlessCheck` While this PR formats Android code, it doesn't modify the iOS one. On Android there weren't that many changes and the number of affected files was low. On iOS there are more changes needed in more files. The idea behind that is that the changed files from now on will have to be reformatted, so the style changes will be more gradual without one huge commit changing the whole codebase. After some time we could make one commit that updates the remaining files, which should result in a clearer history. Also, at some point in the future we should think about updating the `prettier` version the root project is using to match the one in example apps, although it would require reformatting the code. This would allow for handling core, Example and FabricExample code using the same `lint-staged` rule, instead of each one of those having their own. Co-authored-by: kacperkapusciak <kacper.kapusciak@swmansion.com> Co-authored-by: Kacper Kapuściak <39658211+kacperkapusciak@users.noreply.github.com>
1 parent c75146f commit 6dcc759

File tree

62 files changed

+1867
-864
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1867
-864
lines changed

.clang-format

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
---
2+
AccessModifierOffset: -1
3+
AlignAfterOpenBracket: AlwaysBreak
4+
AlignConsecutiveAssignments: false
5+
AlignConsecutiveDeclarations: false
6+
AlignEscapedNewlinesLeft: true
7+
AlignOperands: false
8+
AlignTrailingComments: false
9+
AllowAllParametersOfDeclarationOnNextLine: false
10+
AllowShortBlocksOnASingleLine: false
11+
AllowShortCaseLabelsOnASingleLine: false
12+
AllowShortFunctionsOnASingleLine: Empty
13+
AllowShortIfStatementsOnASingleLine: false
14+
AllowShortLoopsOnASingleLine: false
15+
AlwaysBreakAfterReturnType: None
16+
AlwaysBreakBeforeMultilineStrings: true
17+
AlwaysBreakTemplateDeclarations: true
18+
BinPackArguments: false
19+
BinPackParameters: false
20+
BraceWrapping:
21+
AfterClass: false
22+
AfterControlStatement: false
23+
AfterEnum: false
24+
AfterFunction: false
25+
AfterNamespace: false
26+
AfterObjCDeclaration: false
27+
AfterStruct: false
28+
AfterUnion: false
29+
BeforeCatch: false
30+
BeforeElse: false
31+
IndentBraces: false
32+
BreakBeforeBinaryOperators: None
33+
BreakBeforeBraces: Attach
34+
BreakBeforeTernaryOperators: true
35+
BreakConstructorInitializersBeforeComma: false
36+
BreakAfterJavaFieldAnnotations: false
37+
BreakStringLiterals: false
38+
ColumnLimit: 80
39+
CommentPragmas: '^ IWYU pragma:'
40+
ConstructorInitializerAllOnOneLineOrOnePerLine: true
41+
ConstructorInitializerIndentWidth: 4
42+
ContinuationIndentWidth: 4
43+
Cpp11BracedListStyle: true
44+
DerivePointerAlignment: false
45+
DisableFormat: false
46+
ForEachMacros: [ FOR_EACH_RANGE, FOR_EACH, ]
47+
IncludeCategories:
48+
- Regex: '^<.*\.h(pp)?>'
49+
Priority: 1
50+
- Regex: '^<.*'
51+
Priority: 2
52+
- Regex: '.*'
53+
Priority: 3
54+
IndentCaseLabels: true
55+
IndentWidth: 2
56+
IndentWrappedFunctionNames: false
57+
KeepEmptyLinesAtTheStartOfBlocks: false
58+
MacroBlockBegin: ''
59+
MacroBlockEnd: ''
60+
MaxEmptyLinesToKeep: 1
61+
NamespaceIndentation: None
62+
ObjCBlockIndentWidth: 2
63+
ObjCSpaceAfterProperty: true
64+
ObjCSpaceBeforeProtocolList: true
65+
PenaltyBreakBeforeFirstCallParameter: 1
66+
PenaltyBreakComment: 300
67+
PenaltyBreakFirstLessLess: 120
68+
PenaltyBreakString: 1000
69+
PenaltyExcessCharacter: 1000000
70+
PenaltyReturnTypeOnItsOwnLine: 200
71+
PointerAlignment: Right
72+
ReflowComments: true
73+
SortIncludes: true
74+
SpaceAfterCStyleCast: false
75+
SpaceBeforeAssignmentOperators: true
76+
SpaceBeforeParens: ControlStatements
77+
SpaceInEmptyParentheses: false
78+
SpacesBeforeTrailingComments: 1
79+
SpacesInAngles: false
80+
SpacesInContainerLiterals: true
81+
SpacesInCStyleCastParentheses: false
82+
SpacesInParentheses: false
83+
SpacesInSquareBrackets: false
84+
Standard: Cpp11
85+
TabWidth: 8
86+
UseTab: Never
87+
---
88+
Language: ObjC
89+
ColumnLimit: 120
90+
BreakBeforeBraces: WebKit
91+
...

.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"ts-ignore": "allow-with-description",
5959
"ts-expect-error": "allow-with-description"
6060
}
61-
]
61+
],
62+
"curly": "error"
6263
}
6364
}

.github/workflows/kotlin-lint.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Kotlin Lint
2+
on:
3+
pull_request:
4+
paths:
5+
- 'android/**'
6+
push:
7+
branches:
8+
- main
9+
jobs:
10+
check:
11+
runs-on: ubuntu-latest
12+
concurrency:
13+
group: kotlin-lint-${{ github.ref }}
14+
cancel-in-progress: true
15+
steps:
16+
- name: checkout
17+
uses: actions/checkout@v2
18+
19+
- name: Use Node.js 16
20+
uses: actions/setup-node@v2
21+
with:
22+
node-version: 16
23+
cache: 'yarn'
24+
25+
- uses: actions/cache@v2
26+
with:
27+
path: '**/node_modules'
28+
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}
29+
30+
- name: Install node dependencies
31+
run: yarn install --frozen-lockfile
32+
33+
- name: Restore build from cache
34+
uses: actions/cache@v3
35+
with:
36+
path: |
37+
~/.gradle/caches
38+
~/.gradle/wrapper
39+
android/build
40+
android/.gradle
41+
key: ${{ runner.os }}-kotlin-lint-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties', 'android/build.gradle') }}
42+
43+
- name: Lint
44+
run: yarn lint:android

.github/workflows/static-root-checks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ jobs:
2626
- name: Check types
2727
run: yarn tsc --noEmit
2828
- name: Lint
29-
run: yarn lint-check
29+
run: yarn lint:js-root

.husky/pre-commit

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env sh
2+
. "$(dirname -- "$0")/_/husky.sh"
3+
4+
yarn lint-staged
5+
yarn ts-check

.prettierrc renamed to .prettierrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"jsxBracketSameLine": true,
2+
"bracketSameLine": true,
33
"printWidth": 80,
44
"tabWidth": 2,
55
"semi": true,

FabricExample/.prettierrc.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,5 @@
44
"tabWidth": 2,
55
"semi": true,
66
"singleQuote": true,
7-
"trailingComma": "es5",
8-
"quoteProps": "consistent"
7+
"trailingComma": "es5"
98
}

FabricExample/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@
2828
"@babel/core": "^7.12.9",
2929
"@babel/preset-env": "^7.1.6",
3030
"@babel/runtime": "^7.12.5",
31-
"@react-native-community/eslint-config": "^3.0.0",
31+
"@react-native-community/eslint-config": "^2.0.0",
3232
"babel-jest": "^26.6.3",
33-
"eslint": "^8.12.0",
33+
"eslint": "^7.15.0",
3434
"jest": "^26.6.3",
3535
"metro-react-native-babel-preset": "^0.72.1",
3636
"mkdirp": "^1.0.4",
37-
"prettier": "^2.6.1",
37+
"prettier": "^2.2.1",
3838
"react-test-renderer": "^18.1.0",
3939
"typescript": "^4.5.5"
4040
},

0 commit comments

Comments
 (0)