Skip to content

Commit

Permalink
feat: Implement ESLint and Prettier (#179)
Browse files Browse the repository at this point in the history
* Rewrite GitHub Actions as separate Lint, Test, and Typecheck jobs
* Fix broken ESLint setup and integrate with Prettier
* Run formatter and apply auto-fixes
  • Loading branch information
amattu2 authored Jun 19, 2024
1 parent fde4814 commit 9d08ec1
Show file tree
Hide file tree
Showing 122 changed files with 18,475 additions and 30,303 deletions.
103 changes: 103 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/**
* @type {import("eslint").Linter.Config}
*/
const config = {
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"airbnb",
"airbnb-typescript",
"prettier",
"react-app",
"react-app/jest",
],
globals: {
window: true,
document: true,
},
parser: "@typescript-eslint/parser",
parserOptions: {
ecmaFeatures: {
jsx: true,
},
ecmaVersion: 11,
project: "./tsconfig.json",
sourceType: "module",
},
plugins: ["react", "@typescript-eslint", "prettier"],
settings: {
react: {
pragma: "React",
fragment: "Fragment",
version: "detect",
},
},
root: true,
rules: {
/* base prettier rule */
"prettier/prettier": "error",

"max-len": "off",
"no-console": "warn",
"no-param-reassign": "off",
"object-curly-newline": "off",
"no-underscore-dangle": ["off"],
"arrow-body-style": ["warn"],
"eol-last": ["warn"],
"no-unreachable": ["warn"],
"no-continue": "off",

/* typescript-eslint overwritten rules */
"no-use-before-define": "off",
"no-unused-vars": "off",
"no-loss-of-precision": "off",
"no-shadow": "off",
"no-empty-function": "off",

/* react rules */
"react/prop-types": "off",
"react/jsx-filename-extension": [1, { extensions: [".js", ".jsx", ".tsx", ".ts"] }],
"react/jsx-props-no-spreading": "off",
"react/react-in-jsx-scope": "off",
"react/require-default-props": "off",
"react/jsx-max-props-per-line": [1, { maximum: 1, when: "multiline" }],
"react/function-component-definition": [
"error",
{
namedComponents: "arrow-function",
unnamedComponents: "arrow-function",
},
],
"react/jsx-key": [
"error",
{
checkFragmentShorthand: true,
checkKeyMustBeforeSpread: true,
warnOnDuplicates: true,
},
],
"react/destructuring-assignment": ["error", "always", { destructureInSignature: "always" }],

/* typescript-eslint rules */
"@typescript-eslint/no-empty-function": "error",
"@typescript-eslint/no-use-before-define": "error",
"@typescript-eslint/no-unused-vars": "warn",
"@typescript-eslint/no-loss-of-precision": "error",
"@typescript-eslint/no-redundant-type-constituents": "error",
"@typescript-eslint/no-non-null-asserted-optional-chain": "error",
"@typescript-eslint/no-shadow": "off",
"@typescript-eslint/dot-notation": "off",
"@typescript-eslint/naming-convention": "off",
"@typescript-eslint/ban-ts-comment": "off",

/* create-react-app rules */
"react-hooks/exhaustive-deps": "off",
"import/prefer-default-export": "off",
"import/no-extraneous-dependencies": ["error", { devDependencies: true }],

/* jest and testing-library rules */
"testing-library/prefer-screen-queries": "off",
},
};

module.exports = config;
54 changes: 0 additions & 54 deletions .eslintrc.js

This file was deleted.

37 changes: 0 additions & 37 deletions .github/workflows/code-certify.yml

This file was deleted.

35 changes: 0 additions & 35 deletions .github/workflows/codeql-analysis.yml

This file was deleted.

45 changes: 45 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: CodeQL

on:
workflow_dispatch:
push:
branches:
- "main"
- "master"
- "dev"
- "development"
pull_request:
branches: "*"
schedule:
- cron: '16 23 * * 4'

jobs:
analyze:
name: Analyze (${{ matrix.language }})
runs-on: ubuntu-latest
timeout-minutes: 360
permissions:
security-events: write
packages: read

strategy:
fail-fast: false
matrix:
include:
- language: javascript-typescript
build-mode: none

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }}

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"
43 changes: 43 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: ESLint

on:
workflow_dispatch:
push:
branches:
- "main"
- "master"
- "dev"
- "development"
pull_request:
branches: "*"

permissions:
contents: read

jobs:
lint:
name: Lint Changes
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: "20.x"
cache: "npm"

- name: Cache node modules
uses: actions/cache@v3
with:
path: node_modules
key: ${{ runner.os }}-modules-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-modules-
- name: Install Dependencies
run: npm install

- name: Run ESLint
run: npm run lint:ci
46 changes: 46 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Jest

on:
workflow_dispatch:
push:
branches:
- "main"
- "master"
- "dev"
- "development"
pull_request:
branches: "*"

permissions:
contents: read

jobs:
test:
name: Test Changes
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: "20.x"
cache: "npm"

- name: Cache node modules
uses: actions/cache@v3
with:
path: node_modules
key: ${{ runner.os }}-modules-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-modules-
- name: Install Dependencies
run: npm install

- name: Run Jest
run: npm run test:ci

- name: Coveralls GitHub Action
uses: coverallsapp/[email protected]
Loading

0 comments on commit 9d08ec1

Please sign in to comment.