Skip to content

Commit 9158b9f

Browse files
Setup linting & formatting tooling (#1)
* Install prettier/eslint * Add editorconfig file * Fix package versions * Configure eslint/prettier * Update nuxt * Setup linting workflow * Remove codeql * Setup engines * Fix linter warnings
1 parent 0d4ed25 commit 9158b9f

File tree

11 files changed

+935
-49
lines changed

11 files changed

+935
-49
lines changed

.editorconfig

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
root=true
2+
3+
[*]
4+
end_of_line = lf
5+
insert_final_newline = true
6+
charset = utf-8
7+
indent_style = tab
8+
trim_trailing_whitespace = true
9+
10+
[*.{yml,yaml}]
11+
indent_style = space

.eslintignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
dist

.eslintrc.js

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
const defaultRules = {
2+
// No console statements in production
3+
'no-console': process.env.NODE_ENV !== 'development' ? 'error' : 'off',
4+
// No debugger statements in production
5+
'no-debugger': process.env.NODE_ENV !== 'development' ? 'error' : 'off',
6+
// Enforce prettier formatting
7+
'prettier/prettier': 'error',
8+
'padding-line-between-statements': [
9+
'error',
10+
{
11+
blankLine: 'always',
12+
prev: [
13+
'block',
14+
'block-like',
15+
'cjs-export',
16+
'class',
17+
'export',
18+
'import',
19+
'multiline-block-like',
20+
'multiline-const',
21+
'multiline-expression',
22+
'multiline-let',
23+
'multiline-var',
24+
],
25+
next: '*',
26+
},
27+
{
28+
blankLine: 'always',
29+
prev: ['const', 'let'],
30+
next: ['block', 'block-like', 'cjs-export', 'class', 'export', 'import'],
31+
},
32+
{
33+
blankLine: 'always',
34+
prev: '*',
35+
next: ['multiline-block-like', 'multiline-const', 'multiline-expression', 'multiline-let', 'multiline-var'],
36+
},
37+
{ blankLine: 'any', prev: ['export', 'import'], next: ['export', 'import'] },
38+
],
39+
'lines-between-class-members': ['error', 'always', { exceptAfterSingleLine: true }],
40+
'no-nested-ternary': 'error',
41+
curly: ['error', 'multi-line'],
42+
};
43+
44+
module.exports = {
45+
// Stop looking for ESLint configurations in parent folders
46+
root: true,
47+
// Global variables: Browser and Node.js
48+
env: {
49+
browser: true,
50+
node: true,
51+
},
52+
// Basic configuration for js files
53+
plugins: ['@typescript-eslint', 'prettier'],
54+
extends: ['eslint:recommended', 'prettier'],
55+
rules: defaultRules,
56+
parserOptions: {
57+
ecmaVersion: 2022,
58+
sourceType: 'module',
59+
},
60+
overrides: [
61+
// Configuration for ts/vue files
62+
{
63+
files: ['*.ts', '*.vue'],
64+
parser: 'vue-eslint-parser',
65+
parserOptions: {
66+
parser: '@typescript-eslint/parser',
67+
},
68+
extends: [
69+
'plugin:vue/vue3-recommended',
70+
'eslint:recommended',
71+
'plugin:@typescript-eslint/recommended',
72+
'prettier',
73+
],
74+
rules: {
75+
...defaultRules,
76+
'vue/multi-word-component-names': 'off',
77+
'vue/require-default-prop': 'off',
78+
// It's recommended to turn off this rule on TypeScript projects
79+
'no-undef': 'off',
80+
// Allow ts-directive comments (used to suppress TypeScript compiler errors)
81+
'@typescript-eslint/ban-ts-comment': 'off',
82+
// Allow usage of the any type (consider to enable this rule later on)
83+
'@typescript-eslint/no-explicit-any': 'off',
84+
// Allow usage of require statements (consider to enable this rule later on)
85+
'@typescript-eslint/no-var-requires': 'off',
86+
// Allow non-null assertions for now (consider to enable this rule later on)
87+
'@typescript-eslint/no-non-null-assertion': 'off',
88+
// Allow unused arguments and variables when they begin with an underscore
89+
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_', varsIgnorePattern: '^_' }],
90+
},
91+
},
92+
],
93+
};

.github/actions/prepare/action.yml

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Prepare
2+
description: Install and build the app
3+
inputs:
4+
registry:
5+
description: NPM registry to set up for auth
6+
required: false
7+
8+
runs:
9+
using: 'composite'
10+
steps:
11+
- name: Install Node.js
12+
uses: actions/setup-node@v3
13+
with:
14+
node-version: 18
15+
registry-url: ${{ inputs.registry }}
16+
17+
- uses: pnpm/action-setup@v2
18+
name: Install pnpm
19+
id: pnpm-install
20+
with:
21+
run_install: false
22+
23+
- name: Get pnpm store directory
24+
id: pnpm-cache
25+
shell: bash
26+
run: |
27+
echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT
28+
29+
- uses: actions/cache@v3
30+
name: Setup pnpm cache
31+
with:
32+
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
33+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
34+
restore-keys: |
35+
${{ runner.os }}-pnpm-store-
36+
37+
- name: Install dependencies
38+
shell: bash
39+
run: pnpm install

.github/workflows/lint.yaml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Check
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
concurrency:
12+
group: check-${{ github.ref }}
13+
cancel-in-progress: true
14+
15+
env:
16+
NODE_OPTIONS: --max_old_space_size=6144
17+
18+
jobs:
19+
lint:
20+
name: Lint
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Checkout repository
24+
uses: actions/checkout@v3
25+
26+
- name: Prepare
27+
uses: ./.github/actions/prepare
28+
29+
- name: Run Linter
30+
run: pnpm lint

.prettierignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
dist
2+
coverage
3+
node_modules
4+
pnpm-lock.yaml

.prettierrc.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
htmlWhitespaceSensitivity: 'ignore',
3+
printWidth: 120,
4+
singleQuote: true,
5+
proseWrap: 'always',
6+
};

app.vue

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<div>
3-
<NuxtWelcome />
4-
</div>
2+
<div>
3+
<NuxtWelcome />
4+
</div>
55
</template>

nuxt.config.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
// https://nuxt.com/docs/api/configuration/nuxt-config
22
export default defineNuxtConfig({
3-
devtools: { enabled: true }
4-
})
3+
devtools: { enabled: true },
4+
});

package.json

+28-14
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
11
{
2-
"name": "website",
3-
"private": true,
4-
"scripts": {
5-
"build": "nuxt build",
6-
"dev": "nuxt dev",
7-
"generate": "nuxt generate",
8-
"preview": "nuxt preview",
9-
"postinstall": "nuxt prepare"
10-
},
11-
"devDependencies": {
12-
"@nuxt/devtools": "latest",
13-
"@types/node": "^18",
14-
"nuxt": "^3.5.2"
15-
}
2+
"name": "@directus/website",
3+
"private": true,
4+
"scripts": {
5+
"build": "nuxt build",
6+
"dev": "nuxt dev",
7+
"generate": "nuxt generate",
8+
"preview": "nuxt preview",
9+
"postinstall": "nuxt prepare",
10+
"lint": "eslint .",
11+
"format": "prettier --write \"**/*.{md,y?(a)ml,json,vue}\""
12+
},
13+
"devDependencies": {
14+
"@nuxt/devtools": "latest",
15+
"@types/node": "20.2.5",
16+
"@typescript-eslint/eslint-plugin": "5.59.9",
17+
"@typescript-eslint/parser": "5.59.9",
18+
"eslint": "8.42.0",
19+
"eslint-config-prettier": "8.8.0",
20+
"eslint-plugin-prettier": "4.2.1",
21+
"eslint-plugin-vue": "9.14.1",
22+
"nuxt": "3.5.2",
23+
"prettier": "2.8.8"
24+
},
25+
"packageManager": "[email protected]",
26+
"engines": {
27+
"node": ">=18.0.0",
28+
"pnpm": "~8.6.0"
29+
}
1630
}

0 commit comments

Comments
 (0)