Skip to content

Commit 4372ef4

Browse files
committed
Add ESLint for JavaScript and Vue linting
- Add ESLint 9.x with flat config format - Add eslint-plugin-vue for Vue 3 component linting - Add lint and lint:fix npm scripts - Rename webpack.config.js to webpack.config.cjs for ES modules compatibility - Fix minor linting issues in existing code: - Use v-show instead of v-if with v-for in tabs.vue - Prefix unused catch variable with underscore
1 parent 16fff7e commit 4372ef4

File tree

6 files changed

+582
-30
lines changed

6 files changed

+582
-30
lines changed

.github/scripts/validate-fixtures-json.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,35 +10,35 @@ const path = require('path');
1010
*/
1111
function extractJsonFromHttpFile(filePath) {
1212
const content = fs.readFileSync(filePath, 'utf8');
13-
13+
1414
// Split by double newline to separate headers from body
1515
const parts = content.split(/\n\s*\n/, 2);
16-
16+
1717
if (parts.length < 2) {
1818
return null;
1919
}
20-
20+
2121
const body = parts[1].trim();
2222
if (!body) {
2323
return null;
2424
}
25-
25+
2626
// Check if content-type indicates JSON
2727
const headers = parts[0];
28-
const isJsonContentType = headers.includes('Content-Type: application/json') ||
28+
const isJsonContentType = headers.includes('Content-Type: application/json') ||
2929
headers.includes('content-type: application/json');
30-
30+
3131
// If no explicit JSON content-type, try to parse as JSON anyway
3232
// (some files might have JSON without proper content-type header)
3333
if (!isJsonContentType) {
3434
try {
3535
JSON.parse(body);
3636
return body;
37-
} catch (e) {
37+
} catch (_e) {
3838
return null;
3939
}
4040
}
41-
41+
4242
return body;
4343
}
4444

@@ -49,22 +49,22 @@ function extractJsonFromHttpFile(filePath) {
4949
*/
5050
function findHttpFiles(dir) {
5151
const files = [];
52-
52+
5353
function traverse(currentDir) {
5454
const items = fs.readdirSync(currentDir);
55-
55+
5656
for (const item of items) {
5757
const fullPath = path.join(currentDir, item);
5858
const stat = fs.statSync(fullPath);
59-
59+
6060
if (stat.isDirectory()) {
6161
traverse(fullPath);
6262
} else if (item.endsWith('.http')) {
6363
files.push(fullPath);
6464
}
6565
}
6666
}
67-
67+
6868
traverse(dir);
6969
return files;
7070
}
@@ -77,21 +77,21 @@ function validateJsonInFixtures(fixturesDir) {
7777
const errors = [];
7878
let filesChecked = 0;
7979
let jsonFilesFound = 0;
80-
80+
8181
console.log(`🔍 Scanning for HTTP fixtures in: ${fixturesDir}`);
82-
82+
8383
const httpFiles = findHttpFiles(fixturesDir);
84-
84+
8585
for (const filePath of httpFiles) {
8686
filesChecked++;
8787
const jsonContent = extractJsonFromHttpFile(filePath);
88-
88+
8989
if (!jsonContent) {
9090
continue;
9191
}
92-
92+
9393
jsonFilesFound++;
94-
94+
9595
try {
9696
JSON.parse(jsonContent);
9797
console.log(`✅ ${filePath}`);
@@ -101,12 +101,12 @@ function validateJsonInFixtures(fixturesDir) {
101101
errors.push(errorMsg);
102102
}
103103
}
104-
104+
105105
console.log('\n📊 Summary:');
106106
console.log(`Files checked: ${filesChecked}`);
107107
console.log(`JSON files found: ${jsonFilesFound}`);
108108
console.log(`Validation errors: ${errors.length}`);
109-
109+
110110
if (errors.length > 0) {
111111
console.log('\n❌ Errors found:');
112112
errors.forEach(error => console.log(` ${error}`));

eslint.config.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import js from '@eslint/js';
2+
import pluginVue from 'eslint-plugin-vue';
3+
import globals from 'globals';
4+
5+
export default [
6+
{
7+
ignores: ['dist/', 'output/', 'node_modules/', 'tmp/'],
8+
},
9+
js.configs.recommended,
10+
...pluginVue.configs['flat/recommended'],
11+
{
12+
languageOptions: {
13+
ecmaVersion: 'latest',
14+
sourceType: 'module',
15+
globals: {
16+
...globals.browser,
17+
},
18+
},
19+
rules: {
20+
'no-unused-vars': ['error', { argsIgnorePattern: '^_', caughtErrorsIgnorePattern: '^_' }],
21+
'vue/multi-word-component-names': 'off',
22+
'vue/max-attributes-per-line': 'off',
23+
'vue/html-self-closing': 'off',
24+
'vue/singleline-html-element-content-newline': 'off',
25+
'vue/v-bind-style': 'off',
26+
'vue/attributes-order': 'off',
27+
'vue/no-v-html': 'off',
28+
},
29+
},
30+
{
31+
files: ['webpack.config.cjs', '.github/**/*.js'],
32+
languageOptions: {
33+
sourceType: 'commonjs',
34+
globals: {
35+
...globals.node,
36+
},
37+
},
38+
},
39+
];

package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,25 @@
22
"name": "dnsimple-developer",
33
"version": "0.0.1",
44
"private": true,
5+
"type": "module",
56
"devDependencies": {
7+
"@eslint/js": "^9.18.0",
68
"@fortawesome/fontawesome-free": "^7.1.0",
79
"@redocly/cli": "^2.14.4",
810
"@vue/compiler-sfc": "^3.4.21",
911
"concurrently": "^9.2.1",
1012
"copy-webpack-plugin": "^13.0.1",
13+
"eslint": "^9.18.0",
14+
"eslint-plugin-vue": "^9.32.0",
15+
"globals": "^15.14.0",
1116
"tachyons": "^4.12.0",
1217
"vue-loader": "^17.4.2",
1318
"webpack": "^5.104.1",
1419
"webpack-cli": "^6.0.1"
1520
},
1621
"scripts": {
22+
"lint": "eslint .",
23+
"lint:fix": "eslint . --fix",
1724
"live": "concurrently 'bundle exec nanoc live' 'bundle exec rake compile'",
1825
"build": "npx webpack",
1926
"openapi-lint": "redocly lint content/v2/openapi.yml"

src/components/tabs.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{{ tab }}
55
</div>
66
<div class="tab-content ba pa3 b--moon-gray">
7-
<div v-for="(tab, index) in tabs" :key="`tab${index}`" v-if="currentTab === tab">
7+
<div v-for="(tab, index) in tabs" :key="`tab${index}`" v-show="currentTab === tab">
88
<div v-html="contents[index]"></div>
99
</div>
1010
</div>
File renamed without changes.

0 commit comments

Comments
 (0)