Skip to content

Commit

Permalink
chore: fix precommit hooks (prisma#4316)
Browse files Browse the repository at this point in the history
Co-authored-by: William Luke <william@ordino.ai>
  • Loading branch information
timsuchanek and William Luke authored Nov 30, 2020
1 parent 6bf3c0b commit aa17fbc
Show file tree
Hide file tree
Showing 144 changed files with 4,053 additions and 4,026 deletions.
109 changes: 109 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
const globby = require('globby')
const fs = require('fs')
const path = require('path')

const ignoreFiles = globby.sync('src/packages/*/.eslintignore')

const ignorePatterns = flatten(
flatten(
ignoreFiles.map((f) => {
const dir = path.dirname(f)
return fs
.readFileSync(f, 'utf-8')
.split('\n')
.filter((l) => l.trim().length > 0)
.map((l) => [l, `/${path.join(dir, l)}`])
}),
),
)

module.exports = {
root: true,
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint', 'jest'],
env: {
node: true,
es6: true,
},
extends: [
'eslint:recommended',
'plugin:eslint-comments/recommended',
'plugin:jest/recommended',
],
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
project: ['./src/packages/*/tsconfig.json' /* , 'tsconfig.json' */],
// debugLevel: true,
},
ignorePatterns,
overrides: [
// {
// files: ['*.js'],
// rules: {},
// },
{
files: ['*.ts'],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
'prettier/@typescript-eslint',
'plugin:jest/recommended',
],
rules: {
'@typescript-eslint/no-use-before-define': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'no-useless-escape': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
// added at 2020/11/26
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-empty-function': 'off',
'eslint-comments/no-unlimited-disable': 'off',
'eslint-comments/disable-enable-pair': 'off',
'@typescript-eslint/no-misused-promises': 'off',
'jest/expect-expect': 'off',
'no-empty': 'off',
'jest/valid-title': 'off',
'@typescript-eslint/no-unnecessary-type-assertion': 'off',
// low hanging fruits:
'@typescript-eslint/ban-types': 'off',
'@typescript-eslint/restrict-plus-operands': 'off',
'@typescript-eslint/restrict-template-expressions': 'off',
'jest/no-conditional-expect': 'off',
'jest/no-try-expect': 'off',
'jest/no-export': 'off',
'@typescript-eslint/no-empty-interface': 'off',
},
},
],
settings: {
jest: {
version: 26,
},
},
}

function flatten(input) {
const stack = [...input]
const res = []
while (stack.length) {
// pop value from stack
const next = stack.pop()
if (Array.isArray(next)) {
// push back array items, won't modify the original input
stack.push(...next)
} else {
res.push(next)
}
}
// reverse to restore input order
return res.reverse()
}
4 changes: 3 additions & 1 deletion .github/workflows/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

set -ex

npm i --silent -g pnpm@5.10.4 --unsafe-perm

pnpm i --no-prefer-frozen-lockfile
cd src

npm i --silent -g pnpm@5.10.4 --unsafe-perm
pnpm i --no-prefer-frozen-lockfile

pnpm run setup
42 changes: 42 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,48 @@ jobs:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
if: "!startsWith(github.ref, 'refs/tags/') && github.ref != 'refs/heads/master'"

#
# Linting
#
lint:
timeout-minutes: 5
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
node: [12]

steps:
- uses: actions/checkout@v2

# From https://docs.github.com/en/actions/configuring-and-managing-workflows/caching-dependencies-to-speed-up-workflows#example-using-the-cache-action
- name: Cache node modules
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- uses: actions/setup-node@v2-beta
with:
node-version: ${{ matrix.node }}

- run: bash .github/workflows/setup.sh
env:
CI: true
SKIP_GIT: true
GITHUB_CONTEXT: ${{ toJson(github) }}

- run: pnpm run lint
working-directory: ./

#
# CLI-INTEGRATION-1
#
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ dist/
.vscode
!.vscode/launch.json
coverage

.eslintcache
34 changes: 30 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,32 @@
{
"dependencies": {
"ts-node": "9.0.0",
"typescript": "4.1.2"
}
"private": true,
"scripts": {
"lint": "ts-node scripts/lint.ts",
"precommit-all": "ts-node scripts/lint.ts --staged",
"eslint": "eslint"
},
"devDependencies": {
"@types/node": "^14.14.10",
"@typescript-eslint/eslint-plugin": "^4.8.2",
"@typescript-eslint/parser": "^4.8.2",
"arg": "^5.0.0",
"chalk": "^4.1.0",
"eslint": "^7.14.0",
"eslint-config-prettier": "^6.15.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-jest": "^24.1.3",
"eslint-plugin-prettier": "^3.1.4",
"execa": "^4.1.0",
"globby": "^11.0.1",
"husky": "^4.3.0",
"p-map": "^4.0.0",
"staged-git-files": "^1.2.0",
"ts-node": "9.0.0",
"typescript": "4.1.2"
},
"husky": {
"hooks": {
"pre-commit": "ts-node scripts/lint.ts --staged"
}
}
}
Loading

0 comments on commit aa17fbc

Please sign in to comment.