Skip to content

Commit

Permalink
Add eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
binos30 committed Jul 24, 2024
1 parent e8a581a commit 03e19b6
Show file tree
Hide file tree
Showing 8 changed files with 808 additions and 3 deletions.
13 changes: 13 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,16 @@
/public/assets

/docs/

# Ignore yarn files
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
/yarn-error.log
yarn-debug.log*
.yarn-integrity

.cache/
40 changes: 40 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ jobs:
lint:
runs-on: ubuntu-latest
needs: scan_ruby
permissions:
actions: write
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand All @@ -34,6 +36,44 @@ jobs:
ruby-version: .ruby-version
bundler-cache: true

- name: Set up Node
uses: actions/setup-node@v4
with:
node-version-file: .node-version
cache: "yarn"

- name: Install JavaScript dependencies
env:
YARN_VERSION: 4.3.1
run: |
yarn set version $YARN_VERSION
yarn install --immutable
- name: Restore ESLint cache
uses: actions/cache/restore@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: .cache/eslint
key: eslint-main-cache

- name: Run ESLint
run: yarn eslint-ci

- name: Remove ESLint cache
if: github.event_name == 'push'
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.event.repository.full_name }}
run: |
gh api --method DELETE /repos/{owner}/{repo}/actions/caches?key=eslint-main-cache ||
echo "ESLint cache not found"
- name: Save ESLint cache
if: github.event_name == 'push'
uses: actions/cache/save@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: .cache/eslint
key: eslint-main-cache

- name: Lint code for consistent style
run: |
bin/bundle exec stree check "{app,config,lib,spec,test}/**/*.rb"
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,5 @@
/yarn-error.log
yarn-debug.log*
.yarn-integrity

.cache/
1 change: 1 addition & 0 deletions app/javascript/application.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-undef */
// Entry point for the build script in your package.json
import "@fortawesome/fontawesome-free/js/all.min";
import "@hotwired/turbo-rails";
Expand Down
1 change: 1 addition & 0 deletions app/javascript/components/TurboProgressBar.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-undef */
export default class TurboProgressBar {
constructor() {
this.adapter = Turbo.navigator.delegate.adapter;
Expand Down
22 changes: 22 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import globals from "globals";
import pluginJs from "@eslint/js";

export default [
{ languageOptions: { globals: { ...globals.browser, ...globals.node } } },
pluginJs.configs.recommended,
{
ignores: [
".yarn/",
"app/assets/builds/*",
"db/",
"docs/",
"lib/",
"log/*",
"public/assets/*",
"spec/",
"storage/",
"tmp/",
"vendor/"
]
}
];
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@
"local-time": "^3.0.2"
},
"devDependencies": {
"@eslint/js": "^9.7.0",
"eslint": "9.x",
"globals": "^15.8.0",
"husky": "^9.1.1",
"lint-staged": "^15.2.7",
"prettier": "^3.3.3"
},
"scripts": {
"build": "esbuild app/javascript/*.* --bundle --sourcemap --format=esm --outdir=app/assets/builds --public-path=/assets",
"eslint-ci": "eslint . --cache --cache-strategy content --cache-location .cache/eslint --format gha",
"postinstall": "husky"
},
"lint-staged": {
Expand All @@ -26,7 +30,8 @@
"./bin/rubocop -a"
],
"spec/**/*_spec.rb": "./bin/rspec",
"{app,config}/**/*.{json,js,jsx,ts,tsx,css,scss}": "./node_modules/.bin/prettier --write --ignore-unknown"
"{app,config}/**/*.{json,js,jsx,ts,tsx,css,scss}": "./node_modules/.bin/prettier --write --ignore-unknown",
"**/*.js": "./node_modules/.bin/eslint --cache --cache-strategy content --cache-location .cache/eslint --fix"
},
"packageManager": "yarn@4.3.1"
}
Loading

0 comments on commit 03e19b6

Please sign in to comment.