From 50e6b6bceb63eec7d48365731c451f94e7d631c9 Mon Sep 17 00:00:00 2001 From: ota-meshi Date: Thu, 11 Jan 2024 13:44:40 +0900 Subject: [PATCH] format --- .github/workflows/format.yml | 34 +++++++++++++++++++ .../src/lib/components/ESLintCodeBlock.svelte | 2 +- package.json | 4 +-- src/rules/html-closing-bracket-spacing.ts | 4 +-- src/rules/indent-helpers/es.ts | 8 ++--- src/rules/indent-helpers/index.ts | 4 +-- src/rules/mustache-spacing.ts | 4 +-- src/rules/no-trailing-spaces.ts | 2 +- src/rules/shorthand-attribute.ts | 4 +-- src/shared/svelte-compile-warns/index.ts | 8 ++--- tests/utils/utils.ts | 12 +++---- 11 files changed, 60 insertions(+), 26 deletions(-) create mode 100644 .github/workflows/format.yml diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml new file mode 100644 index 000000000..b157e9045 --- /dev/null +++ b/.github/workflows/format.yml @@ -0,0 +1,34 @@ +name: 👔 Format + +on: + workflow_dispatch: null + +permissions: + contents: write + +jobs: + format: + runs-on: ubuntu-latest + + steps: + - name: Checkout repo + uses: actions/checkout@v4 + - name: Setup node + uses: actions/setup-node@v4 + - name: Install deps + run: pnpm install -f + - name: Format + run: pnpm run lint-fix + - name: Commit + run: | + git config --local user.email "github-actions[bot]@users.noreply.github.com" + git config --local user.name "github-actions[bot]" + + git add . + if [ -z "$(git status --porcelain)" ]; then + echo "no formatting changed" + exit 0 + fi + git commit -m "chore: format" + git push + echo "pushed formatting changes https://github.com/$GITHUB_REPOSITORY/commit/$(git rev-parse HEAD)" diff --git a/docs-svelte-kit/src/lib/components/ESLintCodeBlock.svelte b/docs-svelte-kit/src/lib/components/ESLintCodeBlock.svelte index 30e742a3e..919c3ea17 100644 --- a/docs-svelte-kit/src/lib/components/ESLintCodeBlock.svelte +++ b/docs-svelte-kit/src/lib/components/ESLintCodeBlock.svelte @@ -27,7 +27,7 @@ ? async () => { tsParser = await loadTsParser(); return loadLinter; - } + } : () => loadLinter ); let showDiff = fix; diff --git a/package.json b/package.json index bc126afc7..9531b6ee8 100644 --- a/package.json +++ b/package.json @@ -153,9 +153,9 @@ "nyc": "^15.1.0", "pako": "^2.0.3", "postcss-nested": "^6.0.0", - "prettier": "^3.0.0", + "prettier": "^3.1.1", "prettier-plugin-pkg": "^0.18.0", - "prettier-plugin-svelte": "^3.0.0", + "prettier-plugin-svelte": "^3.1.2", "prism-svelte": "^0.5.0", "prismjs": "^1.25.0", "rimraf": "^5.0.0", diff --git a/src/rules/html-closing-bracket-spacing.ts b/src/rules/html-closing-bracket-spacing.ts index 34bd0280c..20c6daea9 100644 --- a/src/rules/html-closing-bracket-spacing.ts +++ b/src/rules/html-closing-bracket-spacing.ts @@ -84,8 +84,8 @@ export default createRule('html-closing-bracket-spacing', { node.type === 'SvelteEndTag' ? 'endTag' : node.selfClosing - ? 'selfClosingTag' - : 'startTag'; + ? 'selfClosingTag' + : 'startTag'; if (options[tagType] === 'ignore') return; diff --git a/src/rules/indent-helpers/es.ts b/src/rules/indent-helpers/es.ts index b58777ff8..583222a51 100644 --- a/src/rules/indent-helpers/es.ts +++ b/src/rules/indent-helpers/es.ts @@ -338,11 +338,11 @@ export function defineVisitor(context: IndentContext): NodeListener { ? sourceCode.getTokenBefore(node.source, { filter: isClosingBraceToken, includeComments: false - })! + })! : sourceCode.getLastToken(node, { filter: isClosingBraceToken, includeComments: false - })!; + })!; offsets.setOffsetToken(leftBraceTokens, 0, exportToken); offsets.setOffsetElementList( node.specifiers, @@ -535,12 +535,12 @@ export function defineVisitor(context: IndentContext): NodeListener { fromToken: tokens[fromIndex], beforeTokens: tokens.slice(0, fromIndex), afterTokens: [...tokens.slice(fromIndex + 1), sourceCode.getFirstToken(node.source)] - } + } : { fromToken: null, beforeTokens: [...tokens, sourceCode.getFirstToken(node.source)], afterTokens: [] - }; + }; const namedSpecifiers: TSESTree.ImportSpecifier[] = []; for (const specifier of node.specifiers) { diff --git a/src/rules/indent-helpers/index.ts b/src/rules/indent-helpers/index.ts index 258904c77..969c6c83f 100644 --- a/src/rules/indent-helpers/index.ts +++ b/src/rules/indent-helpers/index.ts @@ -127,8 +127,8 @@ export function defineVisitor( actualUnit: mismatchCharIndexes.length ? 'whitespace' : options.indentChar === '\t' - ? 'tab' - : 'space', + ? 'tab' + : 'space', expectedIndentPlural: expectedIndent === 1 ? '' : 's', actualIndentPlural: actualIndent === 1 ? '' : 's' }, diff --git a/src/rules/mustache-spacing.ts b/src/rules/mustache-spacing.ts index e48c9ea3f..4708dfee5 100644 --- a/src/rules/mustache-spacing.ts +++ b/src/rules/mustache-spacing.ts @@ -363,7 +363,7 @@ export default createRule('mustache-spacing', { ? sourceCode.getTokenAfter(openBlockLast, { includeComments: false, filter: isClosingBraceToken - }) + }) : null; verifyBraces( openBlockOpeningToken, @@ -384,7 +384,7 @@ export default createRule('mustache-spacing', { ? sourceCode.getTokenAfter(openBlockLast, { includeComments: false, filter: isClosingBraceToken - }) + }) : null; verifyBraces( openBlockOpeningToken, diff --git a/src/rules/no-trailing-spaces.ts b/src/rules/no-trailing-spaces.ts index 1eee75c24..33b5c72c1 100644 --- a/src/rules/no-trailing-spaces.ts +++ b/src/rules/no-trailing-spaces.ts @@ -76,7 +76,7 @@ export default createRule('no-trailing-spaces', { ...(ignoreComments ? { SvelteHTMLComment: collectIgnoreLineNumbers - } + } : {}), 'Program:exit'() { const lines = sourceCode.lines; diff --git a/src/rules/shorthand-attribute.ts b/src/rules/shorthand-attribute.ts index 702486fed..bdc4f6096 100644 --- a/src/rules/shorthand-attribute.ts +++ b/src/rules/shorthand-attribute.ts @@ -59,7 +59,7 @@ export default createRule('shorthand-attribute', { }); } } - } + } : { SvelteShorthandAttribute(node) { context.report({ @@ -70,6 +70,6 @@ export default createRule('shorthand-attribute', { } }); } - }; + }; } }); diff --git a/src/shared/svelte-compile-warns/index.ts b/src/shared/svelte-compile-warns/index.ts index 52db20268..20e184507 100644 --- a/src/shared/svelte-compile-warns/index.ts +++ b/src/shared/svelte-compile-warns/index.ts @@ -385,8 +385,8 @@ function* transformScripts(context: RuleContext, text: string) { ? transformWithTypescript : transformWithBabel : isUseBabel(context) - ? transformWithBabel - : null; + ? transformWithBabel + : null; const sourceCode = getSourceCode(context); if (transform) { @@ -431,8 +431,8 @@ function getWarningsFromCode( ...(semver.satisfies(compiler.VERSION, '>=4.0.0-0') ? { customElement: true } : hasTagOption(getSourceCode(context).ast) - ? { customElement: true } - : {}) + ? { customElement: true } + : {}) }); return { warnings: result.warnings as Warning[], kind: 'warn' }; diff --git a/tests/utils/utils.ts b/tests/utils/utils.ts index 90fdfe7c8..2efea0830 100644 --- a/tests/utils/utils.ts +++ b/tests/utils/utils.ts @@ -97,7 +97,7 @@ export function loadTestCases( pkgName === 'node' ? { version: process.version } : // eslint-disable-next-line @typescript-eslint/no-require-imports -- test - require(`${pkgName}/package.json`); + require(`${pkgName}/package.json`); return !semver.satisfies(pkg.version, pkgVersion); }) ) { @@ -206,8 +206,8 @@ function writeFixtures(ruleName: string, inputFile: string, { force }: { force?: path.extname(inputFile) === '.svelte' ? 'svelte-eslint-parser' : path.extname(inputFile) === '.ts' - ? '@typescript-eslint/parser' - : undefined; + ? '@typescript-eslint/parser' + : undefined; const { code, filename, options, ...verifyConfig } = config; const result = linter.verify( code, @@ -244,7 +244,7 @@ function writeFixtures(ruleName: string, inputFile: string, { force }: { force?: messageId: s.messageId, // Need to have this be the *fixed* output, not just the fix content or anything output: applySuggestion(config.code, s) - })) + })) : null })) )}` @@ -286,8 +286,8 @@ function getConfig(ruleName: string, inputFile: string) { path.extname(filename) === '.svelte' ? require.resolve('svelte-eslint-parser') : path.extname(inputFile) === '.ts' - ? require.resolve('@typescript-eslint/parser') - : undefined; + ? require.resolve('@typescript-eslint/parser') + : undefined; return Object.assign( {