Skip to content

Commit 6a39ae9

Browse files
committed
feat: simplify configuration
docs: provide examples
1 parent ac23f20 commit 6a39ae9

File tree

2 files changed

+75
-25
lines changed

2 files changed

+75
-25
lines changed

README.md

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,35 @@ To use the recommended configuration, add it to your `eslint.config.js` file. Th
2424

2525
```javascript
2626
// eslint.config.mjs
27-
import tsparser from "@typescript-eslint/parser";
28-
import { defineConfig } from "eslint/config";
2927
import obsidianmd from "eslint-plugin-obsidianmd";
30-
31-
export default defineConfig([
32-
...obsidianmd.configs.recommended,
33-
{
34-
files: ["**/*.ts"],
35-
languageOptions: {
36-
parser: tsparser,
37-
parserOptions: { project: "./tsconfig.json" },
38-
},
39-
40-
// You can add your own configuration to override or add rules
41-
rules: {
42-
// example: turn off a rule from the recommended set
43-
"obsidianmd/sample-names": "off",
44-
// example: add a rule not in the recommended set and set its severity
45-
"obsidianmd/prefer-file-manager-trash": "error",
46-
},
47-
},
48-
]);
49-
28+
import { defineConfig, globalIgnores } from "eslint/config";
29+
30+
export default defineConfig(
31+
globalIgnores([
32+
"node_modules",
33+
"dist",
34+
"esbuild.config.mjs",
35+
"eslint.config.mjs",
36+
"version-bump.mjs"
37+
]),
38+
{
39+
files: [
40+
'**/*.js',
41+
'**/*.jsx',
42+
'**/*.cjs',
43+
'**/*.mjs',
44+
'**/*.ts',
45+
'**/*.tsx',
46+
'**/*.cts',
47+
'**/*.mts',
48+
],
49+
extends: obsidianmd.configs.recommended
50+
},
51+
{
52+
files: ['package.json'],
53+
extends: obsidianmd.configs.packageJson
54+
}
55+
);
5056
```
5157

5258
### Legacy Config (`.eslintrc`)

lib/index.ts

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import depend from 'eslint-plugin-depend';
3232
import globals from "globals";
3333
import fs from "node:fs";
3434
import path from "node:path";
35+
import { cwd } from "node:process";
3536
import { Config, defineConfig, globalIgnores } from "eslint/config";
3637
import type { RuleDefinition, RuleDefinitionTypeOptions, RulesConfig } from "@eslint/core";
3738

@@ -222,7 +223,12 @@ const flatRecommendedConfig: Config[] = defineConfig([
222223
"@microsoft/sdl": sdl,
223224
depend
224225
},
225-
files: ['**/*.js', "**/*.jsx"],
226+
files: [
227+
'**/*.js',
228+
"**/*.jsx",
229+
'**/*.cjs',
230+
'**/*.mjs',
231+
],
226232
extends: tseslint.configs.recommended as Config[],
227233
rules: {
228234
...flatRecommendedGeneralRules,
@@ -235,7 +241,12 @@ const flatRecommendedConfig: Config[] = defineConfig([
235241
"@microsoft/sdl": sdl,
236242
depend
237243
},
238-
files: ['**/*.ts', "**/*.tsx"],
244+
files: [
245+
'**/*.ts',
246+
'**/*.tsx',
247+
'**/*.cts',
248+
'**/*.mts',
249+
],
239250
extends: tseslint.configs.recommendedTypeChecked as Config[],
240251
rules: {
241252
...flatRecommendedGeneralRules,
@@ -269,9 +280,42 @@ const flatRecommendedConfig: Config[] = defineConfig([
269280
sleep: "readonly"
270281
}
271282
},
272-
}
283+
},
284+
{
285+
languageOptions: {
286+
parserOptions: {
287+
ecmaFeatures: {
288+
jsx: true
289+
},
290+
projectService: {
291+
allowDefaultProject: [
292+
'*.js',
293+
'*.jsx',
294+
'*.cjs',
295+
'*.mjs',
296+
],
297+
},
298+
tsconfigRootDir: getRootFolder() ?? ''
299+
},
300+
}
301+
},
302+
globalIgnores([
303+
'node_modules',
304+
])
273305
]);
274306

307+
function getRootFolder(): string | null {
308+
let currentFolder = cwd();
309+
while (currentFolder !== '.' && currentFolder !== '/') {
310+
if (fs.existsSync(path.join(currentFolder, 'package.json'))) {
311+
return currentFolder;
312+
}
313+
currentFolder = path.dirname(currentFolder);
314+
}
315+
316+
return null;
317+
}
318+
275319
const hybridRecommendedConfig: Config[] = defineConfig({
276320
rules: recommendedPluginRulesConfig,
277321
extends: flatRecommendedConfig

0 commit comments

Comments
 (0)