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: sveltejs/eslint-plugin-svelte
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.13.0
Choose a base ref
...
head repository: sveltejs/eslint-plugin-svelte
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.13.1
Choose a head ref
  • 2 commits
  • 9 files changed
  • 1 contributor

Commits on Nov 18, 2021

  1. Fix indent rule bugs (#72)

    ota-meshi authored Nov 18, 2021

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    1f065ef View commit details
  2. 0.13.1

    ota-meshi committed Nov 18, 2021
    Copy the full SHA
    a8e41a4 View commit details
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ota-meshi/eslint-plugin-svelte",
"version": "0.13.0",
"version": "0.13.1",
"publishConfig": {
"access": "public"
},
23 changes: 16 additions & 7 deletions src/rules/indent-helpers/es.ts
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@ import {
isClosingParenToken,
isNotClosingParenToken,
isNotOpeningParenToken,
isNotSemicolonToken,
isOpeningBraceToken,
isOpeningBracketToken,
isOpeningParenToken,
@@ -336,7 +337,10 @@ export function defineVisitor(context: IndentContext): NodeListener {
offsets.setOffsetToken(afterTokens, 1, fromToken)

// assertions
const lastToken = sourceCode.getLastToken(node)!
const lastToken = sourceCode.getLastToken(node, {
filter: isNotSemicolonToken,
includeComments: false,
})!
const assertionTokens = sourceCode.getTokensBetween(
node.source,
lastToken,
@@ -382,10 +386,9 @@ export function defineVisitor(context: IndentContext): NodeListener {
const firstSpecifier = node.specifiers[0]
if (!firstSpecifier || firstSpecifier.type === "ExportSpecifier") {
// export {foo, bar}; or export {foo, bar} from "mod";
const leftBraceTokens = sourceCode.getTokensBetween(
exportToken,
firstSpecifier,
)
const leftBraceTokens = firstSpecifier
? sourceCode.getTokensBetween(exportToken, firstSpecifier)
: [sourceCode.getTokenAfter(exportToken)!]
const rightBraceToken = node.source
? sourceCode.getTokenBefore(node.source, {
filter: isClosingBraceToken,
@@ -417,7 +420,10 @@ export function defineVisitor(context: IndentContext): NodeListener {
)

// assertions
const lastToken = sourceCode.getLastToken(node)!
const lastToken = sourceCode.getLastToken(node, {
filter: isNotSemicolonToken,
includeComments: false,
})!
const assertionTokens = sourceCode.getTokensBetween(
node.source,
lastToken,
@@ -673,7 +679,10 @@ export function defineVisitor(context: IndentContext): NodeListener {
}

// assertions
const lastToken = sourceCode.getLastToken(node)!
const lastToken = sourceCode.getLastToken(node, {
filter: isNotSemicolonToken,
includeComments: false,
})!
const assertionTokens = sourceCode.getTokensBetween(
node.source,
lastToken,
37 changes: 37 additions & 0 deletions tests/fixtures/rules/indent/invalid/script-export02-errors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[
{
"message": "Expected indentation of 2 spaces but found 0 spaces.",
"line": 3,
"column": 1
},
{
"message": "Expected indentation of 2 spaces but found 0 spaces.",
"line": 4,
"column": 1
},
{
"message": "Expected indentation of 2 spaces but found 0 spaces.",
"line": 5,
"column": 1
},
{
"message": "Expected indentation of 2 spaces but found 0 spaces.",
"line": 6,
"column": 1
},
{
"message": "Expected indentation of 2 spaces but found 0 spaces.",
"line": 7,
"column": 1
},
{
"message": "Expected indentation of 2 spaces but found 0 spaces.",
"line": 8,
"column": 1
},
{
"message": "Expected indentation of 2 spaces but found 0 spaces.",
"line": 9,
"column": 1
}
]
12 changes: 12 additions & 0 deletions tests/fixtures/rules/indent/invalid/script-export02-input.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!-- prettier-ignore -->
<script>
export
{
}
;
export
{
}
</script>

<!--tests/fixtures/rules/indent/invalid/script-export02-input.svelte-->
12 changes: 12 additions & 0 deletions tests/fixtures/rules/indent/invalid/script-export02-output.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!-- prettier-ignore -->
<script>
export
{
}
;
export
{
}
</script>

<!--tests/fixtures/rules/indent/invalid/script-export02-input.svelte-->
Original file line number Diff line number Diff line change
@@ -25,12 +25,12 @@
"column": 1
},
{
"message": "Expected indentation of 6 spaces but found 0 spaces.",
"message": "Expected indentation of 4 spaces but found 0 spaces.",
"line": 8,
"column": 1
},
{
"message": "Expected indentation of 4 spaces but found 0 spaces.",
"message": "Expected indentation of 2 spaces but found 0 spaces.",
"line": 9,
"column": 1
}
Original file line number Diff line number Diff line change
@@ -5,8 +5,8 @@
type
:
"json"
}
;
}
;
</script>

<!--tests/fixtures/rules/indent/invalid/ts/ts-import-assertion03-input-->
Original file line number Diff line number Diff line change
@@ -25,12 +25,12 @@
"column": 1
},
{
"message": "Expected indentation of 6 spaces but found 0 spaces.",
"message": "Expected indentation of 4 spaces but found 0 spaces.",
"line": 8,
"column": 1
},
{
"message": "Expected indentation of 4 spaces but found 0 spaces.",
"message": "Expected indentation of 2 spaces but found 0 spaces.",
"line": 9,
"column": 1
}
Original file line number Diff line number Diff line change
@@ -5,8 +5,8 @@
type
:
"json"
}
;
}
;
</script>

<!--tests/fixtures/rules/indent/invalid/ts/ts-import-assertion04-input-->