Skip to content

Commit

Permalink
Add ESLint rule to check for relative imports
Browse files Browse the repository at this point in the history
Relative imports do not work in most Rails apps.
  • Loading branch information
tvdeyen committed Jan 10, 2024
1 parent cfe2983 commit 20e9b2d
Show file tree
Hide file tree
Showing 4 changed files with 474 additions and 8 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,26 @@ jobs:
bundler-cache: true
- name: Lint Ruby files
run: bundle exec standardrb
ESLint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: "18"
- name: Restore node_modules cache
uses: actions/cache@v3
with:
path: node_modules
key: ${{ runner.os }}-node-modules-${{ hashFiles('package.json') }}
restore-keys: |
${{ runner.os }}-node-modules
- name: Install dependencies
run: yarn install
- name: Lint code
run: yarn eslint
Prettier:
runs-on: ubuntu-latest
steps:
Expand Down
17 changes: 17 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export default [
{
rules: {
"no-restricted-imports": [
"error",
{
patterns: [
{
group: ["./", "../"],
message: "Relative imports are not allowed."
}
]
}
]
}
}
]
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"scripts": {
"test": "jest",
"lint": "prettier --check 'app/javascript/**/*.js'",
"eslint": "eslint app/javascript/**/*.js",
"build": "rollup -c"
},
"keywords": [],
Expand All @@ -25,6 +26,7 @@
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-terser": "^0.4.4",
"babel-jest": "^29.6.4",
"eslint": "^8.56.0",
"jest": "^29.6.4",
"jest-environment-jsdom": "^29.6.4",
"jquery": "^3.7.1",
Expand Down
Loading

0 comments on commit 20e9b2d

Please sign in to comment.