Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: antfu/eslint-config
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.7.0
Choose a base ref
...
head repository: antfu/eslint-config
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.8.0
Choose a head ref
  • 3 commits
  • 10 files changed
  • 2 contributors

Commits on Mar 4, 2024

  1. feat: add prettier-plugin-astro for eslint-config formatter (#413)

    Kaivan Wong authored Mar 4, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    dtolnay David Tolnay
    Copy the full SHA
    479c47f View commit details
  2. chore: update deps

    antfu committed Mar 4, 2024
    Copy the full SHA
    aae1690 View commit details
  3. chore: release v2.8.0

    antfu committed Mar 4, 2024
    Copy the full SHA
    ac2e713 View commit details
Showing with 839 additions and 360 deletions.
  1. +14 −0 fixtures/input/astro.astro
  2. +17 −3 fixtures/output/all/astro.astro
  3. +21 −0 fixtures/output/with-formatters/astro.astro
  4. +14 −9 package.json
  5. +731 −345 pnpm-lock.yaml
  6. +2 −1 src/cli/constants.ts
  7. +7 −1 src/configs/astro.ts
  8. +25 −1 src/configs/formatters.ts
  9. +7 −0 src/types.ts
  10. +1 −0 test/fixtures.test.ts
14 changes: 14 additions & 0 deletions fixtures/input/astro.astro
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
---
const isJsx = true
const content = "hi!";
---

<article>
<div>{content}</div>
<div>
{isJsx && (
<h1>{content}</h1>
)}
</div>
</article>


<script>
document.querySelector('h1')?.addEventListener('click', () => {
alert('hi!');
});

</script>
20 changes: 17 additions & 3 deletions fixtures/output/all/astro.astro
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
---
const isJsx = true
const content = 'hi!';
---

<article>
<div>{content}</div>
</article>
<article>
<div>{content}</div>
<div>
{isJsx && (
<h1>{content}</h1>
)}
</div>
</article>


<script>
document.querySelector('h1')?.addEventListener('click', () => {
alert('hi!');
});

</script>
21 changes: 21 additions & 0 deletions fixtures/output/with-formatters/astro.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
const isJsx = true
const content = 'hi!';
---

<article>
<div>{content}</div>
<div>
{isJsx && (
<h1>{content}</h1>
)}
</div>
</article>


<script>
document.querySelector('h1')?.addEventListener('click', () => {
alert('hi!');
});

</script>
23 changes: 14 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@antfu/eslint-config",
"type": "module",
"version": "2.7.0",
"version": "2.8.0",
"packageManager": "pnpm@8.15.4",
"description": "Anthony's ESLint config",
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
@@ -46,6 +46,7 @@
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.4",
"eslint-plugin-svelte": "^2.34.1",
"prettier-plugin-astro": "^0.13.0",
"prettier-plugin-slidev": "^1.0.5",
"svelte-eslint-parser": "^0.33.1"
},
@@ -74,6 +75,9 @@
"eslint-plugin-svelte": {
"optional": true
},
"prettier-plugin-astro": {
"optional": true
},
"prettier-plugin-slidev": {
"optional": true
},
@@ -88,8 +92,8 @@
"@eslint-types/typescript-eslint": "^7.0.2",
"@eslint-types/unicorn": "^51.0.1",
"@stylistic/eslint-plugin": "^1.6.3",
"@typescript-eslint/eslint-plugin": "^7.1.0",
"@typescript-eslint/parser": "^7.1.0",
"@typescript-eslint/eslint-plugin": "^7.1.1",
"@typescript-eslint/parser": "^7.1.1",
"eslint-config-flat-gitignore": "^0.1.3",
"eslint-merge-processors": "^0.1.0",
"eslint-plugin-antfu": "^2.1.2",
@@ -131,24 +135,25 @@
"@types/yargs": "^17.0.32",
"@unocss/eslint-plugin": "^0.58.5",
"astro-eslint-parser": "^0.16.3",
"bumpp": "^9.3.0",
"eslint": "npm:eslint-ts-patch@^8.56.0-0",
"bumpp": "^9.4.0",
"eslint": "npm:eslint-ts-patch@^8.57.0-0",
"eslint-flat-config-viewer": "^0.1.11",
"eslint-plugin-astro": "^0.31.4",
"eslint-plugin-format": "^0.1.0",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react": "^7.34.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.5",
"eslint-plugin-svelte": "^2.35.1",
"eslint-ts-patch": "^8.56.0-0",
"esno": "^4.0.0",
"eslint-ts-patch": "^8.57.0-0",
"esno": "^4.7.0",
"execa": "^8.0.1",
"fast-glob": "^3.3.2",
"fs-extra": "^11.2.0",
"lint-staged": "^15.2.2",
"prettier-plugin-astro": "^0.13.0",
"prettier-plugin-slidev": "^1.0.5",
"rimraf": "^5.0.5",
"simple-git-hooks": "^2.9.0",
"simple-git-hooks": "^2.10.0",
"svelte": "^4.2.12",
"svelte-eslint-parser": "^0.33.1",
"tsup": "^8.0.2",
1,076 changes: 731 additions & 345 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/cli/constants.ts
Original file line number Diff line number Diff line change
@@ -49,6 +49,7 @@ export const vscodeSettingsString = `
"json",
"jsonc",
"yaml",
"toml"
"toml",
"astro",
]
`
8 changes: 7 additions & 1 deletion src/configs/astro.ts
Original file line number Diff line number Diff line change
@@ -43,7 +43,13 @@ export async function astro(
'astro/semi': 'off',

...stylistic
? {}
? {
'style/indent': 'off',
'style/jsx-closing-tag-location': 'off',
'style/jsx-indent': 'off',
'style/jsx-one-expression-per-line': 'off',
'style/no-multiple-empty-lines': 'off',
}
: {},

...overrides,
26 changes: 25 additions & 1 deletion src/configs/formatters.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isPackageExists } from 'local-pkg'
import { GLOB_CSS, GLOB_LESS, GLOB_MARKDOWN, GLOB_POSTCSS, GLOB_SCSS } from '../globs'
import { GLOB_ASTRO, GLOB_CSS, GLOB_LESS, GLOB_MARKDOWN, GLOB_POSTCSS, GLOB_SCSS } from '../globs'
import type { VendoredPrettierOptions } from '../vender/prettier-types'
import { ensurePackages, interopDefault, parserPlain } from '../utils'
import type { FlatConfigItem, OptionsFormatters, StylisticConfig } from '../types'
@@ -11,6 +11,7 @@ export async function formatters(
): Promise<FlatConfigItem[]> {
if (options === true) {
options = {
astro: isPackageExists('astro'),
css: true,
graphql: true,
html: true,
@@ -22,6 +23,7 @@ export async function formatters(
await ensurePackages([
'eslint-plugin-format',
options.markdown && options.slidev ? 'prettier-plugin-slidev' : undefined,
options.astro ? 'prettier-plugin-astro' : undefined,
])

if (options.slidev && options.markdown !== true && options.markdown !== 'prettier')
@@ -201,6 +203,28 @@ export async function formatters(
}
}

if (options.astro) {
configs.push({
files: [GLOB_ASTRO],
languageOptions: {
parser: parserPlain,
},
name: 'antfu:formatter:astro',
rules: {
'format/prettier': [
'error',
{
...prettierOptions,
parser: 'astro',
plugins: [
'prettier-plugin-astro',
],
},
],
},
})
}

if (options.graphql) {
configs.push({
files: ['**/*.graphql'],
7 changes: 7 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -152,6 +152,13 @@ export interface OptionsFormatters {
slidev?: boolean | {
files?: string[]
}

/**
* Enable formatting support for Astro.
*
* Currently only support Prettier.
*/
astro?: 'prettier' | boolean
}

export interface OptionsComponentExts {
1 change: 1 addition & 0 deletions test/fixtures.test.ts
Original file line number Diff line number Diff line change
@@ -62,6 +62,7 @@ runWithConfig(
{
typescript: true,
vue: true,
astro: true,
formatters: true,
},
)