This repository has been archived by the owner on Sep 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
createConfig
utility function
- Loading branch information
1 parent
2e893a1
commit 394fce4
Showing
7 changed files
with
140 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import { createConfig } from "./plugin" | ||
export = createConfig |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,21 @@ | ||
import { defineConfig } from 'eslint-define-config' | ||
import { TS, Nuxt, Vue, Prettier } from './utils' | ||
import { removeUnusedItems } from './utils' | ||
import { defineConfig as defineEslintConfig } from 'eslint-define-config' | ||
import { createConfig } from './plugin' | ||
|
||
export = defineConfig({ | ||
extends: removeUnusedItems([ | ||
'./javascript', | ||
Nuxt ? './nuxt' : '', | ||
Vue && !Nuxt ?'./vue' : '', | ||
TS ? './typescript' : '', | ||
|
||
// Devrait toujours être dernier | ||
Prettier ? './prettier' : '' | ||
]) | ||
/** | ||
* Config par défaut qui sera utilisée si eslint est configuré | ||
* de cette façon. | ||
* | ||
* @example | ||
* ``` | ||
* { | ||
* extends: [ | ||
* 'alsacreations' | ||
* ] | ||
* } | ||
* ``` | ||
*/ | ||
export = defineEslintConfig({ | ||
extends: [ | ||
createConfig() | ||
] | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { defineConfig as defineEslintConfig } from 'eslint-define-config' | ||
import { TS, Nuxt, Vue, Prettier, initUtils, removeUnusedItems } from './utils' | ||
import { writeFileSync } from 'fs' | ||
import { resolve } from 'path' | ||
|
||
export type PluginOptions = { | ||
ignore?: ( | ||
| 'vue' | ||
| 'nuxt' | ||
| 'typescript' | ||
| 'prettier' | ||
)[] | ||
} | ||
|
||
/** | ||
* Création d'un fichier .json qui correspond à la config souhaitée. | ||
* Permet dans des cas particuliers de paramétrer les presets que l'on souhaite. | ||
* | ||
* @param options | ||
* @returns Le chemin vers le fichier .json qui pourra être passé à eslint dans la clé `extends` | ||
*/ | ||
export function createConfig(options?: PluginOptions) { | ||
const { | ||
ignore = [] | ||
} = options ?? {} | ||
|
||
initUtils(ignore) | ||
|
||
const config = defineEslintConfig({ | ||
extends: removeUnusedItems([ | ||
'./javascript', | ||
Nuxt ? './nuxt' : '', | ||
Vue && !Nuxt ?'./vue' : '', | ||
TS ? './typescript' : '', | ||
|
||
// Devrait toujours être dernier | ||
Prettier ? './prettier' : '' | ||
]) | ||
}) | ||
|
||
const configPath = resolve(__dirname, 'config.json') | ||
|
||
writeFileSync( | ||
configPath, | ||
JSON.stringify(config) | ||
) | ||
|
||
return configPath | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters