Skip to content

Commit

Permalink
introduce prettier/eslint configs and github flows from Expensify tem…
Browse files Browse the repository at this point in the history
…plate
  • Loading branch information
robertKozik committed Jan 15, 2024
1 parent e8cae9c commit d968cad
Show file tree
Hide file tree
Showing 15 changed files with 1,123 additions and 90 deletions.
7 changes: 6 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
**/node_modules/*
parser/react-native-live-markdown-parser.js
**/react-native-live-markdown-parser.js
*.test.*
example/**/*
*.config.js
.eslintrc.js
.prettierrc.js
24 changes: 14 additions & 10 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = {
tsconfigRootDir: __dirname,
},
extends: [
'expensify',
'plugin:@typescript-eslint/recommended',
'prettier',
'plugin:import/typescript',
Expand All @@ -24,17 +25,20 @@ module.exports = {
},
root: true,
rules: {
'prettier/prettier': [
'error',
'rulesdir/prefer-underscore-method': 'off',
'react/jsx-props-no-spreading': 'off',
'react/require-default-props': 'off',
'react/jsx-filename-extension': ['error', { extensions: ['.tsx', '.jsx'] }],
"import/extensions": [
"error",
"ignorePackages",
{
quoteProps: 'consistent',
singleQuote: true,
tabWidth: 2,
trailingComma: 'es5',
useTabs: false,
},
],
'curly': 'error',
"js": "never",
"jsx": "never",
"ts": "never",
"tsx": "never"
}
],
'import/no-unresolved': 'error',
'import/consistent-type-specifier-style': ['error', 'prefer-top-level'],
'react/jsx-uses-vars': 'error',
Expand Down
Binary file added .github/OSBotify private key.gpg
Binary file not shown.
18 changes: 18 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!-- If necessary, assign reviewers that know the area or changes well. Feel free to tag any additional reviewers you see fit. -->

### Details
<!-- Explanation of the change or anything fishy that is going on -->

### Related Issues
<!-- Please replace GH_LINK with the link to the GitHub issue this Pull Request is related to -->
GH_LINK

### Manual Tests
<!---
Most changes should have accompanying tests. Describe the tests you added or if no tests were added an explanation about why one was not needed.
--->

### Linked PRs
<!---
Please include links to any update PRs in repos that must change their package.json version.
--->
39 changes: 39 additions & 0 deletions .github/workflows/cla.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: CLA Assistant

on:
issue_comment:
types: [created]
pull_request_target:
types: [opened, closed, synchronize]

jobs:
CLA:
runs-on: ubuntu-latest
# This job only runs for pull request comments or pull request target events (not issue comments)
if: github.event.issue.pull_request || github.event_name == 'pull_request_target'
steps:
- uses: actions-ecosystem/action-regex-match@9c35fe9ac1840239939c59e5db8839422eed8a73
id: sign
with:
text: ${{ github.event.comment.body }}
regex: '\s*I have read the CLA Document and I hereby sign the CLA\s*'
- uses: actions-ecosystem/action-regex-match@9c35fe9ac1840239939c59e5db8839422eed8a73
id: recheck
with:
text: ${{ github.event.comment.body }}
regex: '\s*recheck\s*'
- name: CLA Assistant
if: ${{ steps.recheck.outputs.match != '' || steps.sign.outputs.match != '' }} || github.event_name == 'pull_request_target'
# Version: 2.1.2-beta
uses: cla-assistant/github-action@948230deb0d44dd38957592f08c6bd934d96d0cf
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PERSONAL_ACCESS_TOKEN : ${{ secrets.CLA_BOTIFY_TOKEN }}
with:
path-to-signatures: '${{ github.repository }}/cla.json'
path-to-document: 'https://github.com/${{ github.repository }}/blob/main/CLA.md'
branch: 'main'
remote-organization-name: 'Expensify'
remote-repository-name: 'CLA'
lock-pullrequest-aftermerge: false
allowlist: 'snyk-bot,OSBotify'
39 changes: 39 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Lint JavaScript

on:
pull_request:
types: [opened, synchronize]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Setup Node
uses: actions/setup-node@v1
with:
node-version: "16.x"

- run: npm ci

- run: npm run lint
env:
CI: true


- name: Verify there's no Prettier diff
run: |
npm run prettier -- --loglevel silent
if ! git diff --name-only --exit-code; then
# shellcheck disable=SC2016
echo 'Error: Prettier diff detected! Please run `npm run prettier` and commit the changes.'
exit 1
fi
87 changes: 87 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# name: Publish package to npmjs

# # This workflow runs when code is pushed to `main` (i.e: when a pull request is merged)
# on:
# push:
# branches: [main]

# # Ensure that only once instance of this workflow executes at a time.
# # If multiple PRs are merged in quick succession, there will only ever be one publish workflow running and one pending.
# concurrency: ${{ github.workflow }}

# jobs:
# version:
# runs-on: ubuntu-latest

# # OSBotify will update the version on `main`, so this check is important to prevent an infinite loop
# if: ${{ github.actor != 'OSBotify' }}

# steps:
# - uses: actions/checkout@v3
# with:
# ref: main

# - name: Decrypt & Import OSBotify GPG key
# run: |
# cd .github
# gpg --quiet --batch --yes --decrypt --passphrase="$LARGE_SECRET_PASSPHRASE" --output OSBotify-private-key.asc OSBotify-private-key.asc.gpg
# gpg --import OSBotify-private-key.asc
# env:
# LARGE_SECRET_PASSPHRASE: ${{ secrets.LARGE_SECRET_PASSPHRASE }}

# - name: Set up git for OSBotify
# run: |
# git config --global user.signingkey 367811D53E34168C
# git config --global commit.gpgsign true
# git config --global user.name OSBotify
# git config --global user.email [email protected]

# - uses: actions/setup-node@v3
# with:
# node-version: '16.x'
# registry-url: 'https://registry.npmjs.org'

# - name: Generate branch name
# run: echo "BRANCH_NAME=OSBotify-bump-version-$(uuidgen)" >> $GITHUB_ENV

# - name: Create branch for version-bump pull request
# run: git checkout -b ${{ env.BRANCH_NAME }}

# - name: Install npm packages
# run: npm ci

# - name: Update npm version
# run: npm version patch

# - name: Set new version in GitHub ENV
# run: echo "NEW_VERSION=$(jq '.version' package.json)" >> $GITHUB_ENV

# - name: Push branch and publish tags
# run: git push --set-upstream origin ${{ env.BRANCH_NAME }} && git push --tags

# - name: Create pull request
# run: |
# gh pr create \
# --title "Update version to ${{ env.NEW_VERSION }}" \
# --body "Update version to ${{ env.NEW_VERSION }}"
# sleep 5
# env:
# GITHUB_TOKEN: ${{ secrets.OS_BOTIFY_TOKEN }}

# - name: Auto-approve pull request
# run: gh pr review --approve ${{ env.BRANCH_NAME }}
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# - name: Auto-merge pull request
# run: gh pr merge --merge --delete-branch ${{ env.BRANCH_NAME }}
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# - name: Build package
# run: npm run build

# - name: Publish to npm
# run: npm publish
# env:
# NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
12 changes: 6 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
# OSX
#
.DS_Store

# XDE
.expo/
# IDE
.idea

# VSCode
.vscode/
jsconfig.json

# NPM file created by GitHub actions
.npmrc

# Xcode
#
build/
*.pbxuser
!default.pbxuser
Expand All @@ -30,7 +31,6 @@ DerivedData
project.xcworkspace

# Android/IJ
#
.classpath
.cxx
.gradle
Expand All @@ -48,11 +48,11 @@ example/ios/Pods
example/vendor/

# node.js
#
node_modules/
npm-debug.log
yarn-debug.log
yarn-error.log
dist/

# BUCK
buck-out/
Expand Down
19 changes: 19 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# The GH actions don't seem to compile and verify themselves well when Prettier is applied to them
.github/actions/javascript/**/index.js
dist/**/*.js
assets/animations
android
ios
vendor
package.json
package-lock.json
yarn.lock
*.html
*.yml
*.yaml
*.css
*.scss
*.md
example/**/*
.eslintrc.js
react-native-live-markdown-parser.js
9 changes: 9 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
tabWidth: 4,
singleQuote: true,
trailingComma: 'all',
bracketSpacing: false,
arrowParens: 'always',
printWidth: 190,
singleAttributePerLine: true,
};
18 changes: 15 additions & 3 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
module.exports = {
presets: ['module:metro-react-native-babel-preset'],
};
module.exports = (api) => {
const isWeb = api.caller((caller) => caller && caller.target === 'web');
if (isWeb) {
return {
// Default browser list is a reasonable preset covering a wide list of non-dead browsers
// https://github.com/browserslist/browserslist#best-practices
targets: 'defaults',
presets: ['@babel/preset-env', '@babel/preset-react'],
};
}

return {
presets: ['module:metro-react-native-babel-preset'],
};
};
6 changes: 3 additions & 3 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -673,11 +673,11 @@ SPEC CHECKSUMS:
Flipper-PeerTalk: 116d8f857dc6ef55c7a5a75ea3ceaafe878aadc9
FlipperKit: 2efad7007d6745a3f95e4034d547be637f89d3f6
fmt: ff9d55029c625d3757ed641535fd4a75fedc7ce9
glog: 04b94705f318337d7ead9e6d17c019bd9b1f6b1b
hermes-engine: 9b9bb14184a11b8ceb4131b09abf634880f0f46d
glog: 791fe035093b84822da7f0870421a25839ca7870
hermes-engine: c0fcd29517813123a2153e9f7943bc30675f5229
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
OpenSSL-Universal: ebc357f1e6bc71fa463ccb2fe676756aff50e88c
RCT-Folly: 424b8c9a7a0b9ab2886ffe9c3b041ef628fd4fb1
RCT-Folly: 85766c3226c7ec638f05ad7cb3cf6a268d6c4241
RCTRequired: f30c3213569b1dc43659ecc549a6536e1e11139e
RCTTypeSafety: e1ed3137728804fa98bce30b70e3da0b8e23054e
React: 54070abee263d5773486987f1cf3a3616710ed52
Expand Down
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
"typecheck": "tsc --noEmit",
"lint": "eslint . --ext .js,.ts,.tsx",
"clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
"prettier": "prettier --write .",
"prettier-watch": "onchange \"**/*.js\" -- prettier --write --ignore-unknown {{changed}}",
"prepare": "bob build",
"release": "release-it"
},
Expand All @@ -54,8 +56,11 @@
"registry": "https://registry.npmjs.org/"
},
"devDependencies": {
"@babel/preset-env": "^7.20.2",
"@babel/preset-react": "^7.18.6",
"@commitlint/config-conventional": "^17.0.2",
"@evilmartians/lefthook": "^1.5.0",
"@lwc/eslint-plugin-lwc": "^1.7.2",
"@react-native/eslint-config": "^0.72.2",
"@release-it/conventional-changelog": "^5.0.0",
"@types/jest": "^28.1.2",
Expand All @@ -65,12 +70,15 @@
"@typescript-eslint/parser": "^6.15.0",
"del-cli": "^5.0.0",
"eslint": "^8.56.0",
"eslint-config-expensify": "^2.0.24",
"eslint-config-prettier": "^8.5.0",
"eslint-import-resolver-alias": "^1.1.2",
"eslint-plugin-deprecation": "^2.0.0",
"eslint-plugin-es": "^4.1.0",
"eslint-plugin-filenames": "^1.3.2",
"eslint-plugin-header": "^3.1.1",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jsx-a11y": "^6.8.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-tsdoc": "^0.2.17",
Expand Down Expand Up @@ -127,13 +135,6 @@
}
}
},
"prettier": {
"quoteProps": "consistent",
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "es5",
"useTabs": false
},
"react-native-builder-bob": {
"source": "src",
"output": "lib",
Expand Down
Loading

0 comments on commit d968cad

Please sign in to comment.