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.12.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.0
Choose a head ref
  • 4 commits
  • 25 files changed
  • 3 contributors

Commits on Nov 6, 2021

  1. Update dependency eslint-plugin-yml to ^0.11.0 (#68)

    Co-authored-by: Renovate Bot <bot@renovateapp.com>
    renovate[bot] and renovate-bot authored Nov 6, 2021
    Copy the full SHA
    113b821 View commit details

Commits on Nov 14, 2021

  1. Copy the full SHA
    2cd9355 View commit details

Commits on Nov 18, 2021

  1. Update indent rule to support typescript v4.5 (#71)

    * Update indent rule to support typescript v4.5
    
    * update
    
    * update
    ota-meshi authored Nov 18, 2021
    Copy the full SHA
    f31be21 View commit details
  2. 0.13.0

    ota-meshi committed Nov 18, 2021
    Copy the full SHA
    2a572ca View commit details
Showing with 820 additions and 19 deletions.
  1. +1 −0 .eslintignore
  2. +8 −8 package.json
  3. +81 −11 src/rules/indent-helpers/es.ts
  4. +21 −0 src/rules/indent-helpers/ts.ts
  5. +32 −0 tests/fixtures/rules/indent/invalid/ts-v5/ts-import-assertion01-errors.json
  6. +11 −0 tests/fixtures/rules/indent/invalid/ts-v5/ts-import-assertion01-input.svelte
  7. +11 −0 tests/fixtures/rules/indent/invalid/ts-v5/ts-import-assertion01-output.svelte
  8. +62 −0 tests/fixtures/rules/indent/invalid/ts-v5/ts-import-assertion02-errors.json
  9. +17 −0 tests/fixtures/rules/indent/invalid/ts-v5/ts-import-assertion02-input.svelte
  10. +17 −0 tests/fixtures/rules/indent/invalid/ts-v5/ts-import-assertion02-output.svelte
  11. +37 −0 tests/fixtures/rules/indent/invalid/ts-v5/ts-import-assertion03-errors.json
  12. +12 −0 tests/fixtures/rules/indent/invalid/ts-v5/ts-import-assertion03-input.svelte
  13. +12 −0 tests/fixtures/rules/indent/invalid/ts-v5/ts-import-assertion03-output.svelte
  14. +37 −0 tests/fixtures/rules/indent/invalid/ts-v5/ts-import-assertion04-errors.json
  15. +12 −0 tests/fixtures/rules/indent/invalid/ts-v5/ts-import-assertion04-input.svelte
  16. +12 −0 tests/fixtures/rules/indent/invalid/ts-v5/ts-import-assertion04-output.svelte
  17. +72 −0 tests/fixtures/rules/indent/invalid/ts/ts-type-only-import-export01-errors.json
  18. +20 −0 tests/fixtures/rules/indent/invalid/ts/ts-type-only-import-export01-input.svelte
  19. +20 −0 tests/fixtures/rules/indent/invalid/ts/ts-type-only-import-export01-output.svelte
  20. +102 −0 tests/fixtures/rules/indent/invalid/ts/ts-type-only-import-export02-errors.json
  21. +25 −0 tests/fixtures/rules/indent/invalid/ts/ts-type-only-import-export02-input.svelte
  22. +25 −0 tests/fixtures/rules/indent/invalid/ts/ts-type-only-import-export02-output.svelte
  23. +117 −0 tests/fixtures/rules/indent/invalid/ts/ts-type-only-import-export03-errors.json
  24. +28 −0 tests/fixtures/rules/indent/invalid/ts/ts-type-only-import-export03-input.svelte
  25. +28 −0 tests/fixtures/rules/indent/invalid/ts/ts-type-only-import-export03-output.svelte
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -8,5 +8,6 @@
!/.github
/prettier-playground
/tests/fixtures/rules/indent/invalid/ts
/tests/fixtures/rules/indent/invalid/ts-v5
/tests/fixtures/rules/valid-compile/invalid/ts
/tests/fixtures/rules/valid-compile/valid/ts
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ota-meshi/eslint-plugin-svelte",
"version": "0.12.0",
"version": "0.13.0",
"publishConfig": {
"access": "public"
},
@@ -65,14 +65,14 @@
},
"devDependencies": {
"@ota-meshi/eslint-plugin": "^0.10.0",
"@types/eslint": "^7.2.10",
"@types/eslint": "^8.0.0",
"@types/eslint-scope": "^3.7.0",
"@types/eslint-visitor-keys": "^1.0.0",
"@types/mocha": "^9.0.0",
"@types/node": "^16.0.0",
"@typescript-eslint/eslint-plugin": "^5.0.0-0",
"@typescript-eslint/parser": "^5.0.0-0",
"@typescript-eslint/parser-v4": "npm:@typescript-eslint/parser@5",
"@typescript-eslint/eslint-plugin": "^5.4.0",
"@typescript-eslint/parser": "^5.4.1-0",
"@typescript-eslint/parser-v4": "npm:@typescript-eslint/parser@4",
"env-cmd": "^10.1.0",
"eslint": "^8.0.0",
"eslint-config-prettier": "^8.3.0",
@@ -86,7 +86,7 @@
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-regexp": "^1.0.0",
"eslint-plugin-vue": "^8.0.0",
"eslint-plugin-yml": "^0.10.0",
"eslint-plugin-yml": "^0.11.0",
"eslint4b": "^7.25.0",
"estree-walker": "^3.0.0",
"locate-character": "^2.0.5",
@@ -98,10 +98,10 @@
"prettier-plugin-svelte": "^2.2.0",
"semver": "^7.3.5",
"stylelint": "^14.0.0",
"stylelint-config-standard": "^23.0.0",
"stylelint-config-standard": "^24.0.0",
"svelte": "^3.37.0",
"ts-node": "^10.0.0",
"typescript": "^4.4.2",
"typescript": "^4.5.2",
"vue-eslint-editor": "^1.1.0",
"vue-eslint-parser": "^8.0.0",
"vuepress": "^1.8.2"
92 changes: 81 additions & 11 deletions src/rules/indent-helpers/es.ts
Original file line number Diff line number Diff line change
@@ -334,6 +334,27 @@ export function defineVisitor(context: IndentContext): NodeListener {
}
offsets.setOffsetToken(fromToken, 0, exportToken)
offsets.setOffsetToken(afterTokens, 1, fromToken)

// assertions
const lastToken = sourceCode.getLastToken(node)!
const assertionTokens = sourceCode.getTokensBetween(
node.source,
lastToken,
)
if (assertionTokens.length) {
const assertToken = assertionTokens.shift()!
offsets.setOffsetToken(assertToken, 0, exportToken)
const assertionOpen = assertionTokens.shift()
if (assertionOpen) {
offsets.setOffsetToken(assertionOpen, 1, assertToken)
offsets.setOffsetElementList(
assertionTokens,
assertionOpen,
lastToken,
1,
)
}
}
},
ExportDefaultDeclaration(node: ESTree.ExportDefaultDeclaration) {
const exportToken = sourceCode.getFirstToken(node)
@@ -365,10 +386,15 @@ export function defineVisitor(context: IndentContext): NodeListener {
exportToken,
firstSpecifier,
)
const rightBraceToken = sourceCode.getLastToken(node, {
filter: isClosingBraceToken,
includeComments: false,
})!
const rightBraceToken = node.source
? sourceCode.getTokenBefore(node.source, {
filter: isClosingBraceToken,
includeComments: false,
})!
: sourceCode.getLastToken(node, {
filter: isClosingBraceToken,
includeComments: false,
})!
offsets.setOffsetToken(leftBraceTokens, 0, exportToken)
offsets.setOffsetElementList(
node.specifiers,
@@ -389,14 +415,41 @@ export function defineVisitor(context: IndentContext): NodeListener {
1,
fromToken,
)

// assertions
const lastToken = sourceCode.getLastToken(node)!
const assertionTokens = sourceCode.getTokensBetween(
node.source,
lastToken,
)
if (assertionTokens.length) {
const assertToken = assertionTokens.shift()!
offsets.setOffsetToken(assertToken, 0, exportToken)
const assertionOpen = assertionTokens.shift()
if (assertionOpen) {
offsets.setOffsetToken(assertionOpen, 1, assertToken)
offsets.setOffsetElementList(
assertionTokens,
assertionOpen,
lastToken,
1,
)
}
}
}
} else {
// maybe babel-eslint
}
}
},
ExportSpecifier(node: ESTree.ExportSpecifier) {
const [firstToken, ...tokens] = sourceCode.getTokens(node)
ExportSpecifier(node: ESTree.ExportSpecifier | ESTree.ImportSpecifier) {
const tokens = sourceCode.getTokens(node)
let firstToken = tokens.shift()!
if (firstToken.value === "type") {
const typeToken = firstToken
firstToken = tokens.shift()!
offsets.setOffsetToken(firstToken, 0, typeToken)
}
offsets.setOffsetToken(tokens, 1, firstToken)
},
ForInStatement(node: ESTree.ForInStatement | ESTree.ForOfStatement) {
@@ -618,6 +671,27 @@ export function defineVisitor(context: IndentContext): NodeListener {
offsets.setOffsetToken(fromToken, 0, importToken)
offsets.setOffsetToken(afterTokens, 1, fromToken)
}

// assertions
const lastToken = sourceCode.getLastToken(node)!
const assertionTokens = sourceCode.getTokensBetween(
node.source,
lastToken,
)
if (assertionTokens.length) {
const assertToken = assertionTokens.shift()!
offsets.setOffsetToken(assertToken, 0, importToken)
const assertionOpen = assertionTokens.shift()
if (assertionOpen) {
offsets.setOffsetToken(assertionOpen, 1, assertToken)
offsets.setOffsetElementList(
assertionTokens,
assertionOpen,
lastToken,
1,
)
}
}
},
ImportExpression(node: ESTree.ImportExpression) {
const firstToken = sourceCode.getFirstToken(node)
@@ -636,11 +710,7 @@ export function defineVisitor(context: IndentContext): NodeListener {
offsets.setOffsetToken(tokens, 1, firstToken)
},
ImportSpecifier(node: ESTree.ImportSpecifier) {
if (node.local.range![0] !== node.imported.range![0]) {
const tokens = sourceCode.getTokens(node)
const firstToken = tokens.shift()!
offsets.setOffsetToken(tokens, 1, firstToken)
}
visitor.ExportSpecifier(node)
},
LabeledStatement(
node: ESTree.LabeledStatement | AST.SvelteReactiveStatement,
21 changes: 21 additions & 0 deletions src/rules/indent-helpers/ts.ts
Original file line number Diff line number Diff line change
@@ -995,6 +995,27 @@ export function defineVisitor(context: IndentContext): NodeListener {
1,
)
},
ImportAttribute(node: TSESTree.ImportAttribute) {
const firstToken = sourceCode.getFirstToken(node)
const keyTokens = getFirstAndLastTokens(sourceCode, node.key)
const prefixTokens = sourceCode.getTokensBetween(
firstToken,
keyTokens.firstToken,
)
offsets.setOffsetToken(prefixTokens, 0, firstToken)

offsets.setOffsetToken(keyTokens.firstToken, 0, firstToken)

const initToken = sourceCode.getFirstToken(node.value)
offsets.setOffsetToken(
[
...sourceCode.getTokensBetween(keyTokens.lastToken, initToken),
initToken,
],
1,
keyTokens.lastToken,
)
},
// ----------------------------------------------------------------------
// SINGLE TOKEN NODES
// ----------------------------------------------------------------------
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[
{
"message": "Expected indentation of 2 spaces but found 0 spaces.",
"line": 3,
"column": 1
},
{
"message": "Expected indentation of 4 spaces but found 0 spaces.",
"line": 4,
"column": 1
},
{
"message": "Expected indentation of 6 spaces but found 0 spaces.",
"line": 5,
"column": 1
},
{
"message": "Expected indentation of 8 spaces but found 0 spaces.",
"line": 6,
"column": 1
},
{
"message": "Expected indentation of 8 spaces but found 0 spaces.",
"line": 7,
"column": 1
},
{
"message": "Expected indentation of 4 spaces but found 0 spaces.",
"line": 8,
"column": 1
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- prettier-ignore -->
<script lang="ts">
import foo from "./foo.json" assert
{
type
:
"json"
}
</script>

<!--tests/fixtures/rules/indent/invalid/ts/ts-import-assertion01-input-->
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- prettier-ignore -->
<script lang="ts">
import foo from "./foo.json" assert
{
type
:
"json"
}
</script>

<!--tests/fixtures/rules/indent/invalid/ts/ts-import-assertion01-input-->
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
[
{
"message": "Expected indentation of 2 spaces but found 0 spaces.",
"line": 3,
"column": 1
},
{
"message": "Expected indentation of 4 spaces but found 0 spaces.",
"line": 4,
"column": 1
},
{
"message": "Expected indentation of 4 spaces but found 0 spaces.",
"line": 5,
"column": 1
},
{
"message": "Expected indentation of 6 spaces but found 0 spaces.",
"line": 6,
"column": 1
},
{
"message": "Expected indentation of 8 spaces but found 0 spaces.",
"line": 7,
"column": 1
},
{
"message": "Expected indentation of 8 spaces but found 0 spaces.",
"line": 8,
"column": 1
},
{
"message": "Expected indentation of 10 spaces but found 0 spaces.",
"line": 9,
"column": 1
},
{
"message": "Expected indentation of 12 spaces but found 0 spaces.",
"line": 10,
"column": 1
},
{
"message": "Expected indentation of 12 spaces but found 0 spaces.",
"line": 11,
"column": 1
},
{
"message": "Expected indentation of 8 spaces but found 0 spaces.",
"line": 12,
"column": 1
},
{
"message": "Expected indentation of 4 spaces but found 0 spaces.",
"line": 13,
"column": 1
},
{
"message": "Expected indentation of 2 spaces but found 0 spaces.",
"line": 14,
"column": 1
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!-- prettier-ignore -->
<script lang="ts">
import(
"./foo.json",
{
assert
:
{
type
:
"json"
}
}
)
</script>

<!--tests/fixtures/rules/indent/invalid/ts/ts-import-assertion02-input-->
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!-- prettier-ignore -->
<script lang="ts">
import(
"./foo.json",
{
assert
:
{
type
:
"json"
}
}
)
</script>

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