-
Notifications
You must be signed in to change notification settings - Fork 27
/
eslint.config.mjs
111 lines (97 loc) · 2.71 KB
/
eslint.config.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// SPDX-FileCopyrightText: 2024 Aleksandr Mezin <mezin.alexander@gmail.com>
//
// SPDX-License-Identifier: GPL-2.0-or-later
import { fileURLToPath } from 'node:url';
import path from 'node:path';
import fs from 'node:fs';
import globals from 'globals';
import ignore from 'ignore';
import ddterm from './lint/ddterm-common.mjs';
const baseDir = fileURLToPath(new URL('./', import.meta.url));
function* gitIgnores(dir = '', stack = undefined) {
if (!stack)
stack = [];
const fullDir = path.join(baseDir, dir);
const ignoreFile = path.join(fullDir, '.gitignore');
const rules = ignore();
try {
rules.add(fs.readFileSync(ignoreFile, 'utf8'));
} catch (ex) {
if (ex.code !== 'ENOENT')
throw ex;
}
stack.push({ rules, dirname: path.basename(dir) });
const children = fs.readdirSync(fullDir, { withFileTypes: true });
for (const child of children) {
const isDir = child.isDirectory();
const name = child.name + (isDir ? '/' : '');
let relPath = name;
let i = stack.length - 1;
while (i >= 0) {
if (stack[i].rules.ignores(relPath)) {
yield path.join(dir, name);
break;
}
relPath = path.join(stack[i].dirname, relPath);
i -= 1;
}
if (i === -1 && isDir)
yield* gitIgnores(relPath, stack);
}
stack.pop();
}
export default [
...ddterm,
{
files: [
'lint/import-resolver.js',
'.github/eslint-formatter.js',
],
languageOptions: {
sourceType: 'commonjs',
globals: globals.node,
},
},
{
files: [
'lint/*.{js,mjs,cjs}',
'.github/eslint-formatter.js',
'.markdownlint{,-cli2}.{mjs,cjs}',
],
languageOptions: {
globals: globals.node,
},
settings: {
'import/resolver': 'node',
'import/core-modules': [],
},
},
{
files: [
'extension.legacy.js',
'prefs.legacy.js',
'ddterm/app/fakeext/misc/extensionUtils.js',
'ddterm/pref/resources.legacy.js',
'ddterm/shell/compat.legacy.js',
'test/extension-legacy/*.js',
'bin/launcher.js',
'tools/translate-esm.js',
],
languageOptions: {
sourceType: 'script',
},
},
{
files: ['ddterm/pref/util.js'],
rules: {
quotes: [
'error',
'single',
{ allowTemplateLiterals: true },
],
},
},
{
ignores: Array.from(gitIgnores()),
},
];