-
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(eslint-config): add a configuration preset for Prettier (#695)
- Loading branch information
1 parent
ebe5b31
commit 039cd90
Showing
15 changed files
with
231 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@bfra.me/eslint-config": minor | ||
--- | ||
|
||
Add a configuration preset for Prettier to format whilst linting. | ||
|
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,38 @@ | ||
import type {Config} from '../config' | ||
import type {Flatten, OptionsIsInEditor, OptionsOverrides} from '../options' | ||
import {interopDefault} from '../plugins' | ||
|
||
/** | ||
* Represents the options for the ESLint Prettier configuration. | ||
*/ | ||
export type PrettierOptions = Flatten<OptionsIsInEditor & OptionsOverrides> | ||
|
||
/** | ||
* Generates an ESLint configuration for Prettier. | ||
* @param options - The options for the Prettier configuration. | ||
* @returns An array of ESLint configurations. | ||
*/ | ||
export async function prettier(options: PrettierOptions = {}): Promise<Config[]> { | ||
const {isInEditor, overrides} = options | ||
const [configPrettier, pluginPrettier] = await Promise.all([ | ||
interopDefault(import('eslint-config-prettier')), | ||
interopDefault(import('eslint-plugin-prettier')), | ||
]) | ||
|
||
return [ | ||
{ | ||
name: '@bfra.me/prettier', | ||
plugins: { | ||
prettier: pluginPrettier, | ||
}, | ||
rules: { | ||
...configPrettier.rules, | ||
...(pluginPrettier.configs?.recommended as Config).rules, | ||
|
||
...(isInEditor ? {} : {'prettier/prettier': 'error'}), | ||
|
||
...overrides, | ||
}, | ||
}, | ||
] | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
24 changes: 24 additions & 0 deletions
24
packages/eslint-config/test/fixtures/output/default/tsx.tsx
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,24 @@ | ||
export function Component1() { | ||
return <div /> | ||
} | ||
|
||
export function jsx2() { | ||
const props = {a: 1, b: 2} | ||
return ( | ||
<a foo="bar" bar={`foo`}> | ||
<div {...props} a={1} b="2"> | ||
Inline Text | ||
</div> | ||
<Component1>Block Text</Component1> | ||
<div> | ||
Mixed | ||
<div>Foo</div> | ||
Text<b> Bar</b> | ||
</div> | ||
<p> | ||
foo<i>bar</i> | ||
<b>baz</b> | ||
</p> | ||
</a> | ||
) | ||
} |
60 changes: 30 additions & 30 deletions
60
packages/eslint-config/test/fixtures/output/default/typescript.ts
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
Oops, something went wrong.