Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make ESLint config stricter #22

Merged
merged 9 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 109 additions & 5 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,112 @@
{
"extends": ["next/core-web-vitals", "prettier"],
"plugins": ["prettier"],
"ignorePatterns": ["**/dist/*.js", "/docs/**", "/out/**"],
"plugins": ["prettier", "@typescript-eslint", "import"],
"parserOptions": {
"project": "./tsconfig.json"
},
"parser": "@typescript-eslint/parser",
arkadiuszbachorski marked this conversation as resolved.
Show resolved Hide resolved
"extends": [
"plugin:@typescript-eslint/strict-type-checked",
"plugin:@typescript-eslint/stylistic-type-checked",
"plugin:import/recommended",
"plugin:import/typescript",
arkadiuszbachorski marked this conversation as resolved.
Show resolved Hide resolved
"next/core-web-vitals",
"prettier"
],
"ignorePatterns": [
"**/dist/*",
"/docs/**",
"/out/**",
"**/jest.config.js",
"**/next.config.js",
"**/postcss.config.js",
"**/tailwind.config.js"
],
"rules": {
"prettier/prettier": "error"
}
"prettier/prettier": "error",
"import/order": [
arkadiuszbachorski marked this conversation as resolved.
Show resolved Hide resolved
"warn",
{
"groups": ["builtin", "external", "internal", ["parent", "sibling"]],
"pathGroupsExcludedImportTypes": ["builtin"],
"newlines-between": "never",
"alphabetize": {
"order": "asc",
"caseInsensitive": true
}
}
],
"import/no-empty-named-blocks": "error",
arkadiuszbachorski marked this conversation as resolved.
Show resolved Hide resolved
"import/no-mutable-exports": "error",
arkadiuszbachorski marked this conversation as resolved.
Show resolved Hide resolved
"import/no-cycle": "error",
arkadiuszbachorski marked this conversation as resolved.
Show resolved Hide resolved
"import/extensions": [
arkadiuszbachorski marked this conversation as resolved.
Show resolved Hide resolved
"warn",
"always",
{
"ts": "never",
"tsx": "never",
"js": "never",
"jsx": "never",
"mjs": "never"
}
],
"import/newline-after-import": "warn",
"import/no-anonymous-default-export": "warn",
arkadiuszbachorski marked this conversation as resolved.
Show resolved Hide resolved
"import/no-default-export": "error",
arkadiuszbachorski marked this conversation as resolved.
Show resolved Hide resolved
"@typescript-eslint/consistent-type-imports": [
arkadiuszbachorski marked this conversation as resolved.
Show resolved Hide resolved
"warn",
{
"prefer": "type-imports",
"fixStyle": "inline-type-imports",
"disallowTypeAnnotations": false
}
],
"@typescript-eslint/no-misused-promises": [
arkadiuszbachorski marked this conversation as resolved.
Show resolved Hide resolved
"error",
{
"checksVoidReturn": {
"attributes": false
}
}
],
"import/no-duplicates": [
"error",
{
"prefer-inline": true
}
],
// false negatives
"import/namespace": ["off"],
"no-empty-pattern": "off",
// make sure to `await` inside try…catch
"@typescript-eslint/return-await": ["error", "in-try-catch"],
"@typescript-eslint/no-confusing-void-expression": [
"error",
{ "ignoreArrowShorthand": true }
],
// empty interfaces are fine, e.g. React component that extends other component, but with no additional props
"@typescript-eslint/no-empty-interface": "off",
"@typescript-eslint/array-type": [
arkadiuszbachorski marked this conversation as resolved.
Show resolved Hide resolved
"warn",
{ "default": "array-simple", "readonly": "array-simple" }
],
// allow unused vars prefixed with `_`
"@typescript-eslint/no-unused-vars": [
"error",
{ "argsIgnorePattern": "^_", "varsIgnorePattern": "^_" }
],
// numbers and booleans are fine in template strings
"@typescript-eslint/restrict-template-expressions": [
arkadiuszbachorski marked this conversation as resolved.
Show resolved Hide resolved
"error",
{ "allowNumber": true, "allowBoolean": true }
],
"react/no-unescaped-entities": "off"
arkadiuszbachorski marked this conversation as resolved.
Show resolved Hide resolved
},
"overrides": [
{
"files": ["app/**/*.ts?(x)"],
arkadiuszbachorski marked this conversation as resolved.
Show resolved Hide resolved
"rules": {
"import/no-default-export": "off"
}
}
]
}
16 changes: 8 additions & 8 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ jobs:
actions: read
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: javascript-typescript
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
- name: Checkout repository
uses: actions/checkout@v4
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: javascript-typescript
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
2 changes: 1 addition & 1 deletion .github/workflows/monthly-markdown-link-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ name: Monthly Markdown Link Check

on:
schedule:
- cron: "0 8 1 * *"
- cron: '0 8 1 * *'

jobs:
markdown_link_check:
Expand Down
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
**/dist
node_modules
4 changes: 2 additions & 2 deletions app/page.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ describe('Home Component', () => {
it('renders the Stanford Biodesign Logo', () => {
render(<Home />)

const imageElement = screen.getByAltText(
const imageElement: HTMLImageElement = screen.getByAltText(
'Stanford Biodesign Logo',
) as HTMLImageElement
)

expect(imageElement).toBeInTheDocument()
expect(imageElement.src).toContain('stanfordbiodesign.png')
Expand Down
2 changes: 1 addition & 1 deletion app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@
//

import Image from 'next/image'
import { generateGreeting } from '@stanfordbdhg/example-package'

Check warning on line 10 in app/page.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

app/page.tsx#L10

[import/order] `@stanfordbdhg/example-package` import should occur before import of `next/image`

Check failure on line 10 in app/page.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

app/page.tsx#L10

[import/no-unresolved] Unable to resolve path to module '@stanfordbdhg/example-package'.

export default function Home() {
const greeting = generateGreeting()

Check failure on line 13 in app/page.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

app/page.tsx#L13

[@typescript-eslint/no-unsafe-assignment] Unsafe assignment of an `any` value.

Check failure on line 13 in app/page.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

app/page.tsx#L13

[@typescript-eslint/no-unsafe-call] Unsafe call of an `any` typed value.

return (
<div className="flex min-h-screen items-center justify-center">
<div className="flex flex-col items-center">
<Image
src={`${process.env.basePath || ''}/stanfordbiodesign.png`}
src={`${process.env.basePath ?? ''}/stanfordbiodesign.png`}
alt="Stanford Biodesign Logo"
width={634}
height={235}
/>
<h1 className="mt-4 text-center text-3xl">{`${greeting.message} to the ${greeting.project}`}</h1>

Check failure on line 24 in app/page.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

app/page.tsx#L24

[@typescript-eslint/no-unsafe-member-access] Unsafe member access .message on an `any` value.

Check failure on line 24 in app/page.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

app/page.tsx#L24

[@typescript-eslint/no-unsafe-member-access] Unsafe member access .project on an `any` value.
</div>
</div>
)
Expand Down
Loading
Loading