From 13e909bfed51630fc740fa901ebaaaf80eda1433 Mon Sep 17 00:00:00 2001 From: vilicvane Date: Sun, 15 Oct 2023 20:58:45 +0800 Subject: [PATCH] Better initial overrides for eslint --- general/src/composables/eslintrc.ts | 63 +++++++++++++------ .../src/composables/vscode-settings.json.ts | 2 + 2 files changed, 46 insertions(+), 19 deletions(-) diff --git a/general/src/composables/eslintrc.ts b/general/src/composables/eslintrc.ts index 71c9cf9..0cd87b4 100644 --- a/general/src/composables/eslintrc.ts +++ b/general/src/composables/eslintrc.ts @@ -1,5 +1,7 @@ import type {JSONFileOptions} from '@magicspace/core'; -import {json} from '@magicspace/core'; +import {json, composable} from '@magicspace/core'; + +import type {ResolvedOptions} from '../library/index.js'; const JSON_OPTIONS: JSONFileOptions = { /** @link https://eslint.org/docs/user-guide/configuring */ @@ -21,21 +23,44 @@ const JSON_OPTIONS: JSONFileOptions = { ], }; -export default json( - '.eslintrc.json', - { - root: true, - ignorePatterns: ['node_modules/'], - extends: ['plugin:@mufan/javascript'], - overrides: [ - {files: '**/*.{js,jsx}'}, - { - files: '**/*.cjs', - parserOptions: { - sourceType: 'script', - }, - }, - ], - }, - JSON_OPTIONS, -); +export default composable(({type}) => { + const esm = type === 'module'; + + return json( + '.eslintrc.json', + { + root: true, + ignorePatterns: ['node_modules/'], + extends: ['plugin:@mufan/javascript'], + overrides: [ + esm + ? { + files: '**/*.{js,mjs}', + parserOptions: { + sourceType: 'module', + }, + } + : { + files: '**/*.{js,cjs}', + parserOptions: { + sourceType: 'script', + }, + }, + esm + ? { + files: '**/*.cjs', + parserOptions: { + sourceType: 'script', + }, + } + : { + files: '**/*.mjs', + parserOptions: { + sourceType: 'module', + }, + }, + ], + }, + JSON_OPTIONS, + ); +}); diff --git a/typescript/src/composables/vscode-settings.json.ts b/typescript/src/composables/vscode-settings.json.ts index 8db65aa..a56c3c2 100644 --- a/typescript/src/composables/vscode-settings.json.ts +++ b/typescript/src/composables/vscode-settings.json.ts @@ -10,6 +10,8 @@ export default composable( data = extendObjectProperties( data, { + 'typescript.preferences.importModuleSpecifier': 'project-relative', + 'typescript.preferences.importModuleSpecifierEnding': 'js', 'typescript.tsdk': 'node_modules/typescript/lib', }, {