├── .github └── workflows │ └── ci.yml ├── .gitignore ├── CHANGELOG.md ├── INTEGRATIONS.md ├── LICENSE ├── OTHER_PLUGINS.md ├── README.md ├── package.json ├── rollup.config.js ├── src ├── block.js ├── index.js ├── mapping.js ├── postprocess.js ├── preprocess.js ├── processor_options.js ├── state.js └── utils.js └── test ├── index.js ├── node_modules └── eslint-plugin-svelte3 │ └── index.js └── samples ├── .eslintrc.js ├── block-filenames ├── .eslintrc.js ├── Input.svelte └── expected.json ├── compiler-error ├── Input.svelte └── expected.json ├── const-tag ├── .eslintrc.js ├── Input.svelte └── expected.json ├── ignore-styles ├── .eslintrc.js ├── Input.svelte └── expected.json ├── indentation ├── .eslintrc.js ├── Input.svelte └── expected.json ├── labels ├── .eslintrc.js ├── Input.svelte └── expected.json ├── line-endings ├── .eslintrc.js ├── Input.svelte ├── expected.json └── preserve_line_endings ├── module-context ├── .eslintrc.js ├── Input.svelte └── expected.json ├── multiline-fixes ├── .eslintrc.js ├── Fixed.svelte ├── Input.svelte └── expected.json ├── scope ├── .eslintrc.js ├── Input.svelte └── expected.json ├── script-reference ├── .eslintrc.js ├── Input.svelte └── expected.json ├── self-assignment ├── .eslintrc.js ├── Input.svelte └── expected.json ├── template-quotes ├── .eslintrc.js ├── Input.svelte └── expected.json ├── typescript-$$globals ├── .eslintrc.js ├── Input.svelte └── expected.json ├── typescript-bind-reference ├── .eslintrc.js ├── Input.svelte └── expected.json ├── typescript-block-filenames ├── .eslintrc.js ├── Input.svelte └── expected.json ├── typescript-imports ├── .eslintrc.js ├── Input.svelte └── expected.json ├── typescript-indentation ├── .eslintrc.js ├── Input.svelte └── expected.json ├── typescript-inline-type-import ├── .eslintrc.js ├── Input.svelte └── expected.json ├── typescript-lazy ├── .eslintrc.js ├── Input.svelte └── expected.json ├── typescript-multiline-fixes ├── .eslintrc.js ├── Fixed.svelte ├── Input.svelte └── expected.json ├── typescript-peer-dependency ├── .eslintrc.js ├── Input.svelte └── expected.json ├── typescript-special-types ├── .eslintrc.js ├── Input.svelte └── expected.json ├── typescript-template-quotes ├── .eslintrc.js ├── Input.svelte └── expected.json ├── typescript-type-aware-rules ├── .eslintrc.js ├── Input.svelte ├── expected.json ├── store.ts └── tsconfig.json ├── typescript-unsafe-member-access ├── .eslintrc.js ├── Input.svelte ├── expected.json ├── external-file.ts └── tsconfig.json ├── typescript ├── .eslintrc.js ├── Input.svelte └── expected.json └── unused-write-only-store ├── .eslintrc.js ├── Input.svelte └── expected.json /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: [push, pull_request] 3 | jobs: 4 | Tests: 5 | runs-on: ${{ matrix.os }} 6 | strategy: 7 | matrix: 8 | node-version: [14, 16, 18] 9 | os: [ubuntu-latest, windows-latest, macOS-latest] 10 | steps: 11 | - run: git config --global core.autocrlf false 12 | - uses: actions/checkout@v1 13 | - uses: actions/setup-node@v1 14 | with: 15 | node-version: ${{ matrix.node-version }} 16 | - run: npm install 17 | - run: npm test 18 | env: 19 | CI: true 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /index.js 2 | /node_modules 3 | /package-lock.json 4 | /pnpm-lock.yaml 5 | /test/samples/*/actual.json 6 | /yarn.lock 7 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # 4.0.0 2 | 3 | - Breaking change: ESLint 8+ is now required 4 | 5 | # 3.4.1 6 | 7 | - Support destructuring in `{@const}` tag 8 | 9 | # 3.4.0 10 | 11 | - Support `{@const}` tag 12 | 13 | # 3.3.0 14 | 15 | - Add injected globals when there's no instance script when using TypeScript 16 | - Allow `$$Props`, `$$Slots`, `$$Events` interface/type usage 17 | - Improve type inference for autosubscribed stores 18 | - Silence false positives for `` 19 | - Use TS 4.5 `preserveValueImports` if it's available 20 | - Improve default setting for `svelte3/ignore-styles`: Now ignores styles if its tag has a `lang` or `type` attribute 21 | - Improve fix range handling 22 | 23 | # 3.2.1 24 | 25 | - Filter `no-undef` messages about `$$Generic` 26 | 27 | # 3.2.0 28 | 29 | - Support lazy-loading TypeScript compiler 30 | - Support non-CommonJS format of ESLint configuration file when using TypeScript by specifying `true` in configuration 31 | - Improve logic for finding the correct `Linter` instance in a workspace with multiple directories 32 | - Improve filtering of `@typescript-eslint/indent` and `@typescript-eslint/quotes` messages like what already happens with `indent` and `quotes` 33 | - Fix erroneous messages when a component only writes to a store 34 | 35 | # 3.1.2 36 | 37 | - Silence some incorrect `unsafe-member-access` errors - see README for current limitations 38 | 39 | # 3.1.1 40 | 41 | - Fix erroneous errors from two-way binding in TypeScript components 42 | - Fix erroneous warnings from the removal of `import`s in TypeScript components 43 | 44 | # 3.1.0 45 | 46 | - Add TypeScript support 47 | 48 | # 3.0.0 49 | 50 | - Breaking change: Node 10+ is now required 51 | - There are no specific changes yet that will not work on Node 8, but tests will no longer be run on Node 8, and there are no guarantees about it 52 | - Fix erroneous `no-unused-vars` for variables that are assigned to in the template, but are only used in the script 53 | 54 | # 2.7.3 55 | 56 | - Fix mishandling of blocks whose last line consists of only the expected indentation 57 | 58 | # 2.7.2 59 | 60 | - Fix regression when using `linebreak-style` with Windows line endings 61 | 62 | # 2.7.1 63 | 64 | - Named code blocks were in fact a breaking change, sorry! 65 | - They're now disabled by default, but can be enabled with `svelte3/named-blocks` 66 | 67 | # 2.7.0 68 | 69 | - Expose the parts of each linted component as separate named code blocks `module.js`, `instance.js`, and `template.js` 70 | 71 | # 2.6.0 72 | 73 | - Add `svelte3/compiler` setting to allow overriding which instance of the Svelte compiler is used 74 | 75 | # 2.5.0 76 | 77 | - Fix `let:` handling on regular elements as well 78 | - Separate `then` and `catch` scopes in `{#await}` 79 | 80 | # 2.4.2 81 | 82 | - Fix handling of the scope created by `let:` directives 83 | 84 | # 2.4.1 85 | 86 | - Fix attribute parsing edge case in `svelte3/ignore-styles` callback 87 | 88 | # 2.4.0 89 | 90 | - Respect `no-self-assign` rule unless self-assignment is to a top-level variable known to the compiler 91 | - Better handling of identifiers containing unicode characters 92 | 93 | # 2.3.0 94 | 95 | - Respect `quotes` rule unless inside a template expression which is inside an attribute or directive enclosed in quotes 96 | - Respect `no-unused-expressions` rule again (which is now safe thanks to a previous refactor) 97 | 98 | # 2.2.2 99 | 100 | - Stop using inline configuration comments internally, to avoid issues with `--no-inline-config` and `--report-unused-disable-directives` 101 | 102 | # 2.2.1 103 | 104 | - Handle `then` and `catch` scope in `{#await}` 105 | 106 | # 2.2.0 107 | 108 | - Enforce semicolon rules in template expressions 109 | - Fix parsing of template expressions that are object literals 110 | - Don't produce multiple messages for template expressions wrapped in parentheses 111 | 112 | # 2.1.0 113 | 114 | - Preserve linting messages about labels other than `$` 115 | 116 | # 2.0.2 117 | 118 | - Actually fix ignoring of rules in the template 119 | 120 | # 2.0.1 121 | 122 | - Disregard `eol-last` rule 123 | - Disregard `no-unused-expressions` rule in the template 124 | - Fix bug where rules intended to only be ignored in the template were being ignored in the entire file 125 | 126 | # v2.0.0 127 | 128 | - Require Svelte v3.2+ and ESLint 6+ 129 | - Reworked configuration: 130 | - `svelte3/enabled` has been removed in favor of registering a `svelte3/svelte3` processor that you need to enable on files 131 | - `svelte3/ignore-warnings` now only takes a callback which is passed the warning object 132 | - `svelte3/compiler-options` now only takes a compiler options object 133 | - `svelte3/ignore-styles` now only takes a preprocessor-style callback 134 | - `svelte3/lint-template` has been removed, and template linting is now always enabled 135 | 136 | # v1.2.3 137 | 138 | - Fix a weird edge case where fixes to problems could be lost in certain cases 139 | 140 | # v1.2.2 141 | 142 | - Internal improvements to AST walk 143 | 144 | # v1.2.1 145 | 146 | - Avoid mutating the AST while linting, which can have adverse effects 147 | 148 | # v1.2.0 149 | 150 | - Pass a second argument to the `svelte3/ignore-warnings` function that contains the entire warning object 151 | - Disregard `no-labels` rule and `no-restricted-syntax` rule in places where it disallows labels 152 | 153 | # v1.1.0 154 | 155 | - Experimental support for linting expressions in the template, behind the `svelte3/lint-template` setting. This feature requires Svelte 3.2.0 156 | 157 | # v1.0.0 158 | 159 | - Svelte v3 release party! 160 | 161 | # v0.4.7 162 | 163 | - Fix regression with specifying an array of warnings to ignore 164 | 165 | # v0.4.6 166 | 167 | - Add `svelte3/compiler-options` setting to control how the compiler is called during linting 168 | 169 | # v0.4.5 170 | 171 | - Proper fix for not wiping tag names that begin with ` Syntax > Open all with current extension as... > HTML**. 43 | 44 | Then, you'll need to tell SublimeLinter-eslint to lint entire files with the `text.html` syntax, and not just the contents of their ` 131 | ``` 132 | 133 | ## Interactions with other plugins 134 | 135 | Care needs to be taken when using this plugin alongside others. Take a look at [this list of things you need to watch out for](OTHER_PLUGINS.md). 136 | 137 | ## Configuration 138 | 139 | There are a few settings you can use to adjust this plugin's behavior. These go in the `settings` object in your ESLint configuration. 140 | 141 | Passing a function as a value for a setting (which some of the settings below require) is only possible when using a CommonJS `.eslintrc.js` file, and not a JSON or YAML configuration file. 142 | 143 | ### `svelte3/ignore-warnings` 144 | 145 | This setting can be given a function that indicates whether to ignore a warning in the linting. The function will be passed a warning object and should return a boolean. Only warnings from the Svelte compiler itself can be filtered out through this function. Regular ESLint rules are configured/disabled through the corresponding ESLint settings. 146 | 147 | The default is to not ignore any warnings. 148 | 149 | ### `svelte3/compiler-options` 150 | 151 | Most compiler options do not affect the validity of compiled components, but a couple of them can. If you are compiling to custom elements, or for some other reason need to control how the plugin compiles the components it's linting, you can use this setting. 152 | 153 | This setting can be given an object of compiler options. 154 | 155 | The default is to compile with `{ generate: false }`. 156 | 157 | ### `svelte3/ignore-styles` 158 | 159 | If you're using some sort of preprocessor on the component styles, then it's likely that when this plugin calls the Svelte compiler on your component, it will throw an exception. In a perfect world, this plugin would be able to apply the preprocessor to the component and then use source maps to translate any warnings back to the original source. In the current reality, however, you can instead simply disregard styles written in anything other than standard CSS. You won't get warnings about the styles from the linter, but your application will still use them (of course) and compiler warnings will still appear in your build logs. 160 | 161 | This setting can be given a function that accepts an object of attributes on a ` 4 | -------------------------------------------------------------------------------- /test/samples/ignore-styles/expected.json: -------------------------------------------------------------------------------- 1 | [] 2 | -------------------------------------------------------------------------------- /test/samples/indentation/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | rules: { 3 | indent: ['error', 'tab'], 4 | semi: 'error', 5 | }, 6 | }; 7 | -------------------------------------------------------------------------------- /test/samples/indentation/Input.svelte: -------------------------------------------------------------------------------- 1 | 5 | -------------------------------------------------------------------------------- /test/samples/indentation/expected.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "ruleId": "semi", 4 | "line": 2, 5 | "column": 5, 6 | "fix": { 7 | "range": [13, 13], 8 | "text": ";" 9 | } 10 | }, 11 | { 12 | "ruleId": "indent", 13 | "line": 3, 14 | "column": 2, 15 | "endLine": 3, 16 | "endColumn": 3, 17 | "fix": { 18 | "range": [15, 16], 19 | "text": "" 20 | } 21 | }, 22 | { 23 | "ruleId": "semi", 24 | "line": 3, 25 | "column": 6, 26 | "fix": { 27 | "range": [19, 19], 28 | "text": ";" 29 | } 30 | } 31 | ] 32 | -------------------------------------------------------------------------------- /test/samples/labels/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | rules: { 3 | 'no-labels': 'error', 4 | 'no-restricted-syntax': ['error', 'LabeledStatement'], 5 | 'no-unused-labels': 'error', 6 | }, 7 | }; 8 | -------------------------------------------------------------------------------- /test/samples/labels/Input.svelte: -------------------------------------------------------------------------------- 1 | 6 | -------------------------------------------------------------------------------- /test/samples/labels/expected.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "ruleId": "no-restricted-syntax", 4 | "line": 2, 5 | "column": 2, 6 | "endLine": 2, 7 | "endColumn": 11 8 | }, 9 | { 10 | "ruleId": "no-labels", 11 | "line": 2, 12 | "column": 2, 13 | "endLine": 2, 14 | "endColumn": 11 15 | }, 16 | { 17 | "ruleId": "no-unused-labels", 18 | "line": 2, 19 | "column": 2, 20 | "endLine": 2, 21 | "endColumn": 5, 22 | "fix": { 23 | "range": [10, 15], 24 | "text": "" 25 | } 26 | }, 27 | { 28 | "ruleId": "no-restricted-syntax", 29 | "line": 4, 30 | "column": 2, 31 | "endLine": 4, 32 | "endColumn": 13 33 | }, 34 | { 35 | "ruleId": "no-labels", 36 | "line": 4, 37 | "column": 2, 38 | "endLine": 4, 39 | "endColumn": 13 40 | }, 41 | { 42 | "ruleId": "no-unused-labels", 43 | "line": 4, 44 | "column": 2, 45 | "endLine": 4, 46 | "endColumn": 6, 47 | "fix": { 48 | "range": [30, 36], 49 | "text": "" 50 | } 51 | } 52 | ] 53 | -------------------------------------------------------------------------------- /test/samples/line-endings/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | rules: { 3 | 'linebreak-style': ['error', 'windows'], 4 | }, 5 | }; 6 | -------------------------------------------------------------------------------- /test/samples/line-endings/Input.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 | 8 | 9 | {foo} 10 | -------------------------------------------------------------------------------- /test/samples/line-endings/expected.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "ruleId": "missing-declaration", 4 | "line": 9, 5 | "column": 2, 6 | "endLine": 9, 7 | "endColumn": 5 8 | } 9 | ] 10 | -------------------------------------------------------------------------------- /test/samples/line-endings/preserve_line_endings: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sveltejs/eslint-plugin-svelte3/92671bee83b1d38979e1b0f2897a987cbd61b808/test/samples/line-endings/preserve_line_endings -------------------------------------------------------------------------------- /test/samples/module-context/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | rules: { 3 | 'no-undef': 'error', 4 | 'no-unused-vars': 'error', 5 | 'prefer-const': 'error', 6 | }, 7 | }; 8 | -------------------------------------------------------------------------------- /test/samples/module-context/Input.svelte: -------------------------------------------------------------------------------- 1 | 5 | 6 | 12 | -------------------------------------------------------------------------------- /test/samples/module-context/expected.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "ruleId": "no-unused-vars", 4 | "line": 2, 5 | "column": 18, 6 | "endLine": 2, 7 | "endColumn": 21 8 | }, 9 | { 10 | "ruleId": "prefer-const", 11 | "line": 3, 12 | "column": 6, 13 | "endLine": 3, 14 | "endColumn": 10 15 | }, 16 | { 17 | "ruleId": "missing-declaration", 18 | "line": 9, 19 | "column": 14, 20 | "endLine": 9, 21 | "endColumn": 19 22 | } 23 | ] 24 | -------------------------------------------------------------------------------- /test/samples/multiline-fixes/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | rules: { 3 | curly: 'error', 4 | 'no-else-return': 'error', 5 | 'no-lonely-if': 'error', 6 | }, 7 | }; 8 | -------------------------------------------------------------------------------- /test/samples/multiline-fixes/Fixed.svelte: -------------------------------------------------------------------------------- 1 | 25 | -------------------------------------------------------------------------------- /test/samples/multiline-fixes/Input.svelte: -------------------------------------------------------------------------------- 1 | 27 | -------------------------------------------------------------------------------- /test/samples/multiline-fixes/expected.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "ruleId": "curly", 4 | "severity": 2, 5 | "message": "Expected { after 'if' condition.", 6 | "line": 3, 7 | "column": 9, 8 | "nodeType": "IfStatement", 9 | "messageId": "missingCurlyAfterCondition", 10 | "endLine": 7, 11 | "endColumn": 25, 12 | "fix": { 13 | "range": [ 14 | 37, 15 | 174 16 | ], 17 | "text": "{window.foo =\n window.bar\n .toLowerCase()\n .replace('something', 'else')\n .trim();}" 18 | } 19 | }, 20 | { 21 | "ruleId": "no-else-return", 22 | "severity": 2, 23 | "message": "Unnecessary 'else' after 'return'.", 24 | "line": 12, 25 | "column": 16, 26 | "nodeType": "BlockStatement", 27 | "messageId": "unexpected", 28 | "endLine": 14, 29 | "endColumn": 10, 30 | "fix": { 31 | "range": [ 32 | 264, 33 | 306 34 | ], 35 | "text": "\n return 'bar';\n " 36 | } 37 | }, 38 | { 39 | "ruleId": "no-lonely-if", 40 | "severity": 2, 41 | "message": "Unexpected if as the only statement in an else block.", 42 | "line": 21, 43 | "column": 13, 44 | "nodeType": "IfStatement", 45 | "messageId": "unexpectedLonelyIf", 46 | "endLine": 23, 47 | "endColumn": 14, 48 | "fix": { 49 | "range": [ 50 | 398, 51 | 468 52 | ], 53 | "text": "if (!window) {\n doY();\n " 54 | } 55 | } 56 | ] -------------------------------------------------------------------------------- /test/samples/scope/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | rules: { 3 | 'no-undef': 'error', 4 | }, 5 | settings: { 6 | 'svelte3/ignore-warnings': ({ code }) => code === 'missing-declaration', 7 | }, 8 | }; 9 | -------------------------------------------------------------------------------- /test/samples/scope/Input.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 | {#each foo as bar} 6 | {bar} 7 | {/each} 8 | 9 | {bar} 10 | 11 | {#each foo as [bar1, { bar2 }]} 12 | {bar1} 13 | {bar2} 14 | {bar3} 15 | {/each} 16 | 17 | 18 | {baz} 19 | 20 | 21 | 22 | {baz1} 23 | {baz2} 24 | {baz3} 25 | 26 | 27 | 28 |
29 | {blah1} 30 | {blah2} 31 |
32 |
33 | 34 | 35 | 36 | {blah1} 37 | {blah2} 38 | 39 | 40 | 41 | {#await foo} 42 | xxx 43 | {:then blah1} 44 | {blah1} 45 | {blah2} 46 | {:catch blah2} 47 | {blah1} 48 | {blah2} 49 | {/await} 50 | 51 | {#await foo then bar} 52 | {bar} 53 | {/await} 54 | -------------------------------------------------------------------------------- /test/samples/scope/expected.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "ruleId": "no-undef", 4 | "line": 9, 5 | "column": 2, 6 | "endLine": 9, 7 | "endColumn": 5 8 | }, 9 | { 10 | "ruleId": "no-undef", 11 | "line": 14, 12 | "column": 3, 13 | "endLine": 14, 14 | "endColumn": 7 15 | }, 16 | { 17 | "ruleId": "no-undef", 18 | "line": 24, 19 | "column": 3, 20 | "endLine": 24, 21 | "endColumn": 7 22 | }, 23 | { 24 | "ruleId": "no-undef", 25 | "line": 29, 26 | "column": 4, 27 | "endLine": 29, 28 | "endColumn": 9 29 | }, 30 | { 31 | "ruleId": "no-undef", 32 | "line": 36, 33 | "column": 4, 34 | "endLine": 36, 35 | "endColumn": 9 36 | }, 37 | { 38 | "ruleId": "no-undef", 39 | "line": 45, 40 | "column": 3, 41 | "endLine": 45, 42 | "endColumn": 8 43 | }, 44 | { 45 | "ruleId": "no-undef", 46 | "line": 47, 47 | "column": 3, 48 | "endLine": 47, 49 | "endColumn": 8 50 | } 51 | ] 52 | -------------------------------------------------------------------------------- /test/samples/script-reference/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | rules: { 3 | 'no-unused-vars': 'error', 4 | }, 5 | }; 6 | -------------------------------------------------------------------------------- /test/samples/script-reference/Input.svelte: -------------------------------------------------------------------------------- 1 | 7 | 8 |
foo = true} on:keyup={() => foo = true}>foo
9 | -------------------------------------------------------------------------------- /test/samples/script-reference/expected.json: -------------------------------------------------------------------------------- 1 | [] 2 | -------------------------------------------------------------------------------- /test/samples/self-assignment/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | rules: { 3 | 'no-self-assign': 'error', 4 | }, 5 | }; 6 | -------------------------------------------------------------------------------- /test/samples/self-assignment/Input.svelte: -------------------------------------------------------------------------------- 1 | 9 | -------------------------------------------------------------------------------- /test/samples/self-assignment/expected.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "ruleId": "no-self-assign", 4 | "line": 6, 5 | "column": 9, 6 | "endLine": 6, 7 | "endColumn": 12 8 | } 9 | ] 10 | -------------------------------------------------------------------------------- /test/samples/template-quotes/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | rules: { 3 | quotes: ['error', 'single'], 4 | }, 5 | }; 6 | -------------------------------------------------------------------------------- /test/samples/template-quotes/Input.svelte: -------------------------------------------------------------------------------- 1 | {'foo'} 2 | {"bar"} 3 |
4 |
5 | -------------------------------------------------------------------------------- /test/samples/template-quotes/expected.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "ruleId": "quotes", 4 | "line": 2, 5 | "column": 2, 6 | "endLine": 2, 7 | "endColumn": 7, 8 | "fix": { 9 | "range": [9, 14], 10 | "text": "'bar'" 11 | } 12 | }, 13 | { 14 | "ruleId": "quotes", 15 | "line": 3, 16 | "column": 13, 17 | "endLine": 3, 18 | "endColumn": 19, 19 | "fix": { 20 | "range": [28, 34], 21 | "text": "'baz1'" 22 | } 23 | } 24 | ] 25 | -------------------------------------------------------------------------------- /test/samples/typescript-$$globals/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | parser: '@typescript-eslint/parser', 3 | extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'], 4 | plugins: ['@typescript-eslint'], 5 | settings: { 6 | 'svelte3/typescript': require('typescript'), 7 | }, 8 | }; 9 | -------------------------------------------------------------------------------- /test/samples/typescript-$$globals/Input.svelte: -------------------------------------------------------------------------------- 1 | {$$slots.foo} 2 | {$$props.bar} 3 | {$$restProps.baz} 4 | -------------------------------------------------------------------------------- /test/samples/typescript-$$globals/expected.json: -------------------------------------------------------------------------------- 1 | [] 2 | -------------------------------------------------------------------------------- /test/samples/typescript-bind-reference/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | parser: '@typescript-eslint/parser', 3 | extends: ['plugin:@typescript-eslint/recommended'], 4 | plugins: ['@typescript-eslint'], 5 | settings: { 6 | 'svelte3/typescript': require('typescript'), 7 | }, 8 | }; 9 | -------------------------------------------------------------------------------- /test/samples/typescript-bind-reference/Input.svelte: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /test/samples/typescript-bind-reference/expected.json: -------------------------------------------------------------------------------- 1 | [] 2 | -------------------------------------------------------------------------------- /test/samples/typescript-block-filenames/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | parser: '@typescript-eslint/parser', 3 | extends: ['plugin:@typescript-eslint/recommended'], 4 | plugins: ['@typescript-eslint'], 5 | overrides: [ 6 | { 7 | files: ['**/*.svelte/*_template.ts'], 8 | rules: { 9 | curly: 'off', 10 | }, 11 | }, 12 | { 13 | files: ['**/*.svelte/*_module.ts'], 14 | rules: { 15 | 'no-undef': 'off', 16 | }, 17 | }, 18 | ], 19 | settings: { 20 | 'svelte3/typescript': require('typescript'), 21 | 'svelte3/named-blocks': true, 22 | }, 23 | rules: { 24 | curly: 'error', 25 | 'no-undef': 'error', 26 | }, 27 | }; 28 | -------------------------------------------------------------------------------- /test/samples/typescript-block-filenames/Input.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 | 9 | 10 |
{ if (foo) bar; }} on:keyup={() => { if (foo) bar; }}>blah
11 | -------------------------------------------------------------------------------- /test/samples/typescript-block-filenames/expected.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "ruleId": "curly", 4 | "line": 2, 5 | "column": 12 6 | }, 7 | { 8 | "ruleId": "curly", 9 | "line": 7, 10 | "column": 11 11 | } 12 | ] 13 | -------------------------------------------------------------------------------- /test/samples/typescript-imports/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | parser: '@typescript-eslint/parser', 3 | plugins: ['@typescript-eslint'], 4 | settings: { 5 | 'svelte3/typescript': require('typescript'), 6 | }, 7 | rules: { 8 | 'no-unused-vars': 'error', 9 | }, 10 | }; 11 | -------------------------------------------------------------------------------- /test/samples/typescript-imports/Input.svelte: -------------------------------------------------------------------------------- 1 | 9 | 10 |
new Thing2()} on:keyup={() => new Thing2()}>
11 | 12 | -------------------------------------------------------------------------------- /test/samples/typescript-imports/expected.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "ruleId": "no-unused-vars", 4 | "severity": 2, 5 | "line": 2, 6 | "column": 22, 7 | "endLine": 2, 8 | "endColumn": 32 9 | }, 10 | { 11 | "ruleId": "no-unused-vars", 12 | "severity": 2, 13 | "line": 4, 14 | "column": 9, 15 | "endLine": 4, 16 | "endColumn": 24 17 | }, 18 | { 19 | "ruleId": "no-unused-vars", 20 | "severity": 2, 21 | "line": 5, 22 | "column": 27, 23 | "endLine": 5, 24 | "endColumn": 38 25 | } 26 | ] 27 | -------------------------------------------------------------------------------- /test/samples/typescript-indentation/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | parser: '@typescript-eslint/parser', 3 | plugins: [ 4 | '@typescript-eslint', 5 | ], 6 | rules: { 7 | indent: 'off', 8 | '@typescript-eslint/indent': ['error', 'tab'], 9 | semi: 'error', 10 | }, 11 | }; 12 | -------------------------------------------------------------------------------- /test/samples/typescript-indentation/Input.svelte: -------------------------------------------------------------------------------- 1 | 5 | 6 |
{foo}
7 | -------------------------------------------------------------------------------- /test/samples/typescript-indentation/expected.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "ruleId": "semi", 4 | "line": 2, 5 | "column": 9, 6 | "fix": { 7 | "range": [27, 27], 8 | "text": ";" 9 | } 10 | }, 11 | { 12 | "ruleId": "@typescript-eslint/indent", 13 | "line": 3, 14 | "column": 2, 15 | "endLine": 3, 16 | "endColumn": 3, 17 | "fix": { 18 | "range": [29, 30], 19 | "text": "" 20 | } 21 | }, 22 | { 23 | "ruleId": "semi", 24 | "line": 3, 25 | "column": 10, 26 | "fix": { 27 | "range": [37, 37], 28 | "text": ";" 29 | } 30 | } 31 | ] 32 | -------------------------------------------------------------------------------- /test/samples/typescript-inline-type-import/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | parser: '@typescript-eslint/parser', 3 | plugins: ['@typescript-eslint'], 4 | settings: { 5 | 'svelte3/typescript': require('typescript'), 6 | }, 7 | rules: { 8 | 'no-unused-vars': 'error', 9 | }, 10 | }; 11 | -------------------------------------------------------------------------------- /test/samples/typescript-inline-type-import/Input.svelte: -------------------------------------------------------------------------------- 1 | 8 | 9 |
new Thing2()} on:keyup={() => new Thing2()}>
10 | 11 | -------------------------------------------------------------------------------- /test/samples/typescript-inline-type-import/expected.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "ruleId": "no-unused-vars", 4 | "severity": 2, 5 | "message": "'UnusedComponent' is defined but never used.", 6 | "line": 3, 7 | "column": 9, 8 | "nodeType": "Identifier", 9 | "messageId": "unusedVar", 10 | "endLine": 3, 11 | "endColumn": 24 12 | }, 13 | { 14 | "ruleId": "no-unused-vars", 15 | "severity": 2, 16 | "message": "'UnusedThing' is defined but never used.", 17 | "line": 4, 18 | "column": 27, 19 | "nodeType": "Identifier", 20 | "messageId": "unusedVar", 21 | "endLine": 4, 22 | "endColumn": 38 23 | }, 24 | { 25 | "ruleId": "no-unused-vars", 26 | "severity": 2, 27 | "message": "'UnusedType' is defined but never used.", 28 | "line": 4, 29 | "column": 56, 30 | "nodeType": "Identifier", 31 | "messageId": "unusedVar", 32 | "endLine": 4, 33 | "endColumn": 66 34 | } 35 | ] 36 | -------------------------------------------------------------------------------- /test/samples/typescript-lazy/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | parser: '@typescript-eslint/parser', 3 | extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'], 4 | plugins: ['@typescript-eslint'], 5 | settings: { 6 | 'svelte3/typescript': () => require('typescript'), 7 | }, 8 | rules: { 9 | indent: ['error', 'tab'], 10 | semi: 'error', 11 | }, 12 | }; 13 | -------------------------------------------------------------------------------- /test/samples/typescript-lazy/Input.svelte: -------------------------------------------------------------------------------- 1 | 5 | 6 | 21 | 22 | {b} 23 |

{x}

24 | -------------------------------------------------------------------------------- /test/samples/typescript-lazy/expected.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "ruleId": "module-script-reactive-declaration", 4 | "severity": 1, 5 | "line": 3, 6 | "column": 2, 7 | "endLine": 3, 8 | "endColumn": 12 9 | }, 10 | { 11 | "ruleId": "no-undef", 12 | "severity": 2, 13 | "line": 3, 14 | "column": 5, 15 | "endLine": 3, 16 | "endColumn": 7 17 | }, 18 | { 19 | "ruleId": "unused-export-let", 20 | "severity": 1, 21 | "line": 7, 22 | "column": 13, 23 | "endLine": 7, 24 | "endColumn": 19 25 | }, 26 | { 27 | "ruleId": "@typescript-eslint/no-explicit-any", 28 | "severity": 1, 29 | "line": 7, 30 | "column": 16, 31 | "endLine": 7, 32 | "endColumn": 19, 33 | "suggestions": [ 34 | { 35 | "messageId": "suggestUnknown", 36 | "fix": { 37 | "range": [ 38 | 58, 39 | 61 40 | ], 41 | "text": "unknown" 42 | }, 43 | "desc": "Use `unknown` instead, this will force you to explicitly, and safely assert the type is correct." 44 | }, 45 | { 46 | "messageId": "suggestNever", 47 | "fix": { 48 | "range": [ 49 | 58, 50 | 61 51 | ], 52 | "text": "never" 53 | }, 54 | "desc": "Use `never` instead, this is useful when instantiating generic type parameters that you don't need to know the type of." 55 | } 56 | ] 57 | }, 58 | { 59 | "ruleId": "indent", 60 | "severity": 2, 61 | "line": 9, 62 | "column": 2, 63 | "endLine": 9, 64 | "endColumn": 3, 65 | "fix": { 66 | "range": [ 67 | 112, 68 | 113 69 | ], 70 | "text": "" 71 | } 72 | }, 73 | { 74 | "ruleId": "@typescript-eslint/no-explicit-any", 75 | "severity": 1, 76 | "line": 9, 77 | "column": 17, 78 | "endLine": 9, 79 | "endColumn": 20, 80 | "suggestions": [ 81 | { 82 | "messageId": "suggestUnknown", 83 | "fix": { 84 | "range": [ 85 | 79, 86 | 82 87 | ], 88 | "text": "unknown" 89 | }, 90 | "desc": "Use `unknown` instead, this will force you to explicitly, and safely assert the type is correct." 91 | }, 92 | { 93 | "messageId": "suggestNever", 94 | "fix": { 95 | "range": [ 96 | 79, 97 | 82 98 | ], 99 | "text": "never" 100 | }, 101 | "desc": "Use `never` instead, this is useful when instantiating generic type parameters that you don't need to know the type of." 102 | } 103 | ] 104 | }, 105 | { 106 | "ruleId": "semi", 107 | "severity": 2, 108 | "line": 9, 109 | "column": 20, 110 | "endLine": 10, 111 | "endColumn": 2, 112 | "fix": { 113 | "range": [ 114 | 130, 115 | 130 116 | ], 117 | "text": ";" 118 | } 119 | }, 120 | { 121 | "ruleId": "@typescript-eslint/no-unused-vars", 122 | "severity": 1, 123 | "line": 12, 124 | "column": 8, 125 | "endLine": 12, 126 | "endColumn": 11 127 | }, 128 | { 129 | "ruleId": "@typescript-eslint/no-empty-interface", 130 | "severity": 2, 131 | "line": 14, 132 | "column": 12, 133 | "endLine": 14, 134 | "endColumn": 13 135 | }, 136 | { 137 | "ruleId": "@typescript-eslint/no-unused-vars", 138 | "severity": 1, 139 | "line": 14, 140 | "column": 12, 141 | "endLine": 14, 142 | "endColumn": 13 143 | }, 144 | { 145 | "ruleId": "@typescript-eslint/no-unused-vars", 146 | "severity": 1, 147 | "line": 16, 148 | "column": 13, 149 | "endLine": 16, 150 | "endColumn": 14 151 | }, 152 | { 153 | "ruleId": "@typescript-eslint/no-empty-function", 154 | "severity": 2, 155 | "line": 16, 156 | "column": 16, 157 | "endLine": 16, 158 | "endColumn": 18 159 | }, 160 | { 161 | "ruleId": "missing-declaration", 162 | "severity": 1, 163 | "line": 23, 164 | "column": 5, 165 | "endLine": 23, 166 | "endColumn": 6 167 | }, 168 | { 169 | "ruleId": "no-undef", 170 | "severity": 2, 171 | "line": 23, 172 | "column": 5, 173 | "endLine": 23, 174 | "endColumn": 6 175 | } 176 | ] 177 | -------------------------------------------------------------------------------- /test/samples/typescript-multiline-fixes/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | parser: '@typescript-eslint/parser', 3 | plugins: ['@typescript-eslint'], 4 | settings: { 5 | 'svelte3/typescript': require('typescript'), 6 | }, 7 | rules: { 8 | curly: 'error', 9 | 'no-else-return': 'error', 10 | 'no-lonely-if': 'error', 11 | }, 12 | }; 13 | -------------------------------------------------------------------------------- /test/samples/typescript-multiline-fixes/Fixed.svelte: -------------------------------------------------------------------------------- 1 | 27 | -------------------------------------------------------------------------------- /test/samples/typescript-multiline-fixes/Input.svelte: -------------------------------------------------------------------------------- 1 | 29 | -------------------------------------------------------------------------------- /test/samples/typescript-multiline-fixes/expected.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "ruleId": "curly", 4 | "severity": 2, 5 | "message": "Expected { after 'if' condition.", 6 | "line": 5, 7 | "column": 9, 8 | "nodeType": "IfStatement", 9 | "messageId": "missingCurlyAfterCondition", 10 | "endLine": 9, 11 | "endColumn": 25, 12 | "fix": { 13 | "range": [ 14 | 69, 15 | 216 16 | ], 17 | "text": "{window.foo =\n window.bar\n .toLowerCase()\n .replace('something' as string, 'else')\n .trim();}" 18 | } 19 | }, 20 | { 21 | "ruleId": "no-else-return", 22 | "severity": 2, 23 | "message": "Unnecessary 'else' after 'return'.", 24 | "line": 14, 25 | "column": 16, 26 | "nodeType": "BlockStatement", 27 | "messageId": "unexpected", 28 | "endLine": 16, 29 | "endColumn": 10, 30 | "fix": { 31 | "range": [ 32 | 314, 33 | 366 34 | ], 35 | "text": "\n return 'bar' as string;\n " 36 | } 37 | }, 38 | { 39 | "ruleId": "no-lonely-if", 40 | "severity": 2, 41 | "message": "Unexpected if as the only statement in an else block.", 42 | "line": 23, 43 | "column": 13, 44 | "nodeType": "IfStatement", 45 | "messageId": "unexpectedLonelyIf", 46 | "endLine": 25, 47 | "endColumn": 14, 48 | "fix": { 49 | "range": [ 50 | 464, 51 | 543 52 | ], 53 | "text": "if (!window) {\n (doY as any)();\n " 54 | } 55 | } 56 | ] -------------------------------------------------------------------------------- /test/samples/typescript-peer-dependency/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | parser: '@typescript-eslint/parser', 3 | extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'], 4 | plugins: ['@typescript-eslint'], 5 | settings: { 6 | 'svelte3/typescript': true, 7 | }, 8 | rules: { 9 | indent: ['error', 'tab'], 10 | semi: 'error', 11 | }, 12 | }; 13 | -------------------------------------------------------------------------------- /test/samples/typescript-peer-dependency/Input.svelte: -------------------------------------------------------------------------------- 1 | 5 | 6 | 21 | 22 | {b} 23 |

{x}

24 | -------------------------------------------------------------------------------- /test/samples/typescript-peer-dependency/expected.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "ruleId": "module-script-reactive-declaration", 4 | "severity": 1, 5 | "line": 3, 6 | "column": 2, 7 | "endLine": 3, 8 | "endColumn": 12 9 | }, 10 | { 11 | "ruleId": "no-undef", 12 | "severity": 2, 13 | "line": 3, 14 | "column": 5, 15 | "endLine": 3, 16 | "endColumn": 7 17 | }, 18 | { 19 | "ruleId": "unused-export-let", 20 | "severity": 1, 21 | "line": 7, 22 | "column": 13, 23 | "endLine": 7, 24 | "endColumn": 19 25 | }, 26 | { 27 | "ruleId": "@typescript-eslint/no-explicit-any", 28 | "severity": 1, 29 | "line": 7, 30 | "column": 16, 31 | "endLine": 7, 32 | "endColumn": 19, 33 | "suggestions": [ 34 | { 35 | "messageId": "suggestUnknown", 36 | "fix": { 37 | "range": [ 38 | 58, 39 | 61 40 | ], 41 | "text": "unknown" 42 | }, 43 | "desc": "Use `unknown` instead, this will force you to explicitly, and safely assert the type is correct." 44 | }, 45 | { 46 | "messageId": "suggestNever", 47 | "fix": { 48 | "range": [ 49 | 58, 50 | 61 51 | ], 52 | "text": "never" 53 | }, 54 | "desc": "Use `never` instead, this is useful when instantiating generic type parameters that you don't need to know the type of." 55 | } 56 | ] 57 | }, 58 | { 59 | "ruleId": "indent", 60 | "severity": 2, 61 | "line": 9, 62 | "column": 2, 63 | "endLine": 9, 64 | "endColumn": 3, 65 | "fix": { 66 | "range": [ 67 | 112, 68 | 113 69 | ], 70 | "text": "" 71 | } 72 | }, 73 | { 74 | "ruleId": "@typescript-eslint/no-explicit-any", 75 | "severity": 1, 76 | "line": 9, 77 | "column": 17, 78 | "endLine": 9, 79 | "endColumn": 20, 80 | "suggestions": [ 81 | { 82 | "messageId": "suggestUnknown", 83 | "fix": { 84 | "range": [ 85 | 79, 86 | 82 87 | ], 88 | "text": "unknown" 89 | }, 90 | "desc": "Use `unknown` instead, this will force you to explicitly, and safely assert the type is correct." 91 | }, 92 | { 93 | "messageId": "suggestNever", 94 | "fix": { 95 | "range": [ 96 | 79, 97 | 82 98 | ], 99 | "text": "never" 100 | }, 101 | "desc": "Use `never` instead, this is useful when instantiating generic type parameters that you don't need to know the type of." 102 | } 103 | ] 104 | }, 105 | { 106 | "ruleId": "semi", 107 | "severity": 2, 108 | "line": 9, 109 | "column": 20, 110 | "endLine": 10, 111 | "endColumn": 2, 112 | "fix": { 113 | "range": [ 114 | 130, 115 | 130 116 | ], 117 | "text": ";" 118 | } 119 | }, 120 | { 121 | "ruleId": "@typescript-eslint/no-unused-vars", 122 | "severity": 1, 123 | "line": 12, 124 | "column": 8, 125 | "endLine": 12, 126 | "endColumn": 11 127 | }, 128 | { 129 | "ruleId": "@typescript-eslint/no-empty-interface", 130 | "severity": 2, 131 | "line": 14, 132 | "column": 12, 133 | "endLine": 14, 134 | "endColumn": 13 135 | }, 136 | { 137 | "ruleId": "@typescript-eslint/no-unused-vars", 138 | "severity": 1, 139 | "line": 14, 140 | "column": 12, 141 | "endLine": 14, 142 | "endColumn": 13 143 | }, 144 | { 145 | "ruleId": "@typescript-eslint/no-unused-vars", 146 | "severity": 1, 147 | "line": 16, 148 | "column": 13, 149 | "endLine": 16, 150 | "endColumn": 14 151 | }, 152 | { 153 | "ruleId": "@typescript-eslint/no-empty-function", 154 | "severity": 2, 155 | "line": 16, 156 | "column": 16, 157 | "endLine": 16, 158 | "endColumn": 18 159 | }, 160 | { 161 | "ruleId": "missing-declaration", 162 | "severity": 1, 163 | "line": 23, 164 | "column": 5, 165 | "endLine": 23, 166 | "endColumn": 6 167 | }, 168 | { 169 | "ruleId": "no-undef", 170 | "severity": 2, 171 | "line": 23, 172 | "column": 5, 173 | "endLine": 23, 174 | "endColumn": 6 175 | } 176 | ] 177 | -------------------------------------------------------------------------------- /test/samples/typescript-special-types/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | parser: '@typescript-eslint/parser', 3 | extends: ['plugin:@typescript-eslint/recommended'], 4 | plugins: ['@typescript-eslint'], 5 | settings: { 6 | 'svelte3/typescript': require('typescript'), 7 | }, 8 | rules: { 9 | 'no-undef': 'error', 10 | }, 11 | }; 12 | -------------------------------------------------------------------------------- /test/samples/typescript-special-types/Input.svelte: -------------------------------------------------------------------------------- 1 | 23 | 24 | {#each items as item} 25 | 26 | {/each} 27 | 28 | {#if message} 29 | {message} 30 | {/if} 31 | -------------------------------------------------------------------------------- /test/samples/typescript-special-types/expected.json: -------------------------------------------------------------------------------- 1 | [] 2 | -------------------------------------------------------------------------------- /test/samples/typescript-template-quotes/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | parser: '@typescript-eslint/parser', 3 | plugins: [ 4 | '@typescript-eslint', 5 | ], 6 | rules: { 7 | quotes: 'off', 8 | '@typescript-eslint/quotes': ['error', 'single'] 9 | }, 10 | }; 11 | -------------------------------------------------------------------------------- /test/samples/typescript-template-quotes/Input.svelte: -------------------------------------------------------------------------------- 1 | {'foo'} 2 | {"bar"} 3 |
4 |
5 | -------------------------------------------------------------------------------- /test/samples/typescript-template-quotes/expected.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "ruleId": "@typescript-eslint/quotes", 4 | "line": 2, 5 | "column": 2, 6 | "endLine": 2, 7 | "endColumn": 7, 8 | "fix": { 9 | "range": [9, 14], 10 | "text": "'bar'" 11 | } 12 | }, 13 | { 14 | "ruleId": "@typescript-eslint/quotes", 15 | "line": 3, 16 | "column": 13, 17 | "endLine": 3, 18 | "endColumn": 19, 19 | "fix": { 20 | "range": [28, 34], 21 | "text": "'baz1'" 22 | } 23 | } 24 | ] 25 | -------------------------------------------------------------------------------- /test/samples/typescript-type-aware-rules/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | parser: '@typescript-eslint/parser', 3 | extends: [ 4 | 'eslint:recommended', 5 | 'plugin:@typescript-eslint/recommended', 6 | 'plugin:@typescript-eslint/recommended-requiring-type-checking',], 7 | plugins: ['@typescript-eslint'], 8 | parserOptions: { 9 | tsconfigRootDir: __dirname, 10 | project: ['./tsconfig.json'], 11 | extraFileExtensions: ['.svelte'], 12 | }, 13 | ignorePatterns: ['.eslintrc.js'], 14 | settings: { 15 | 'svelte3/typescript': require('typescript'), 16 | } 17 | }; 18 | -------------------------------------------------------------------------------- /test/samples/typescript-type-aware-rules/Input.svelte: -------------------------------------------------------------------------------- 1 | 14 | 15 | {$g().slice(2)} 16 | -------------------------------------------------------------------------------- /test/samples/typescript-type-aware-rules/expected.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "ruleId": "@typescript-eslint/no-for-in-array", 4 | "severity": 2, 5 | "line": 3, 6 | "column": 2, 7 | "endLine": 5, 8 | "endColumn": 3 9 | }, 10 | { 11 | "ruleId": "@typescript-eslint/no-unsafe-return", 12 | "severity": 2, 13 | "line": 8, 14 | "column": 3, 15 | "endLine": 8, 16 | "endColumn": 19 17 | }, 18 | { 19 | "ruleId": "@typescript-eslint/no-explicit-any", 20 | "severity": 1, 21 | "line": 8, 22 | "column": 15, 23 | "endLine": 8, 24 | "endColumn": 18, 25 | "suggestions": [ 26 | { 27 | "messageId": "suggestUnknown", 28 | "fix": { 29 | "range": [ 30 | 269, 31 | 272 32 | ], 33 | "text": "unknown" 34 | }, 35 | "desc": "Use `unknown` instead, this will force you to explicitly, and safely assert the type is correct." 36 | }, 37 | { 38 | "messageId": "suggestNever", 39 | "fix": { 40 | "range": [ 41 | 269, 42 | 272 43 | ], 44 | "text": "never" 45 | }, 46 | "desc": "Use `never` instead, this is useful when instantiating generic type parameters that you don't need to know the type of." 47 | } 48 | ] 49 | }, 50 | { 51 | "ruleId": "@typescript-eslint/no-unsafe-member-access", 52 | "severity": 2, 53 | "line": 11, 54 | "column": 2, 55 | "endLine": 11, 56 | "endColumn": 13 57 | }, 58 | { 59 | "ruleId": "@typescript-eslint/no-unsafe-call", 60 | "severity": 2, 61 | "line": 11, 62 | "column": 2, 63 | "endLine": 11, 64 | "endColumn": 13 65 | }, 66 | { 67 | "ruleId": "@typescript-eslint/no-floating-promises", 68 | "severity": 2, 69 | "line": 12, 70 | "column": 2, 71 | "endLine": 12, 72 | "endColumn": 7 73 | } 74 | ] 75 | -------------------------------------------------------------------------------- /test/samples/typescript-type-aware-rules/store.ts: -------------------------------------------------------------------------------- 1 | import { readable, writable } from 'svelte/store'; 2 | 3 | export const f = readable(async () => "hello"); 4 | export const g = writable(() => "world"); 5 | -------------------------------------------------------------------------------- /test/samples/typescript-type-aware-rules/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "include": ["**/*"] 3 | } 4 | -------------------------------------------------------------------------------- /test/samples/typescript-unsafe-member-access/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | parser: "@typescript-eslint/parser", 3 | plugins: [ 4 | "@typescript-eslint", 5 | ], 6 | parserOptions: { 7 | project: ["./tsconfig.json"], 8 | tsconfigRootDir: __dirname, 9 | extraFileExtensions: [".svelte"], 10 | }, 11 | settings: { 12 | "svelte3/typescript": require("typescript"), 13 | }, 14 | rules: { 15 | "@typescript-eslint/no-unsafe-member-access": "error", 16 | }, 17 | }; 18 | -------------------------------------------------------------------------------- /test/samples/typescript-unsafe-member-access/Input.svelte: -------------------------------------------------------------------------------- 1 | 8 | 9 | 30 | 31 | {context_safe.length} 32 | {context_unsafe.length} 33 | {external_safe.length} 34 | {external_unsafe.length} 35 | {instance_safe.length} 36 | {instance_unsafe.length} 37 | 38 | {reactive_unsafe.length} 39 | 40 | {$writable_unsafe.length} 41 | -------------------------------------------------------------------------------- /test/samples/typescript-unsafe-member-access/expected.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "ruleId": "@typescript-eslint/no-unsafe-member-access", 4 | "severity": 2, 5 | "line": 6, 6 | "column": 14, 7 | "endLine": 6, 8 | "endColumn": 35 9 | }, 10 | { 11 | "ruleId": "@typescript-eslint/no-unsafe-member-access", 12 | "severity": 2, 13 | "line": 20, 14 | "column": 14, 15 | "endLine": 20, 16 | "endColumn": 35 17 | }, 18 | { 19 | "ruleId": "@typescript-eslint/no-unsafe-member-access", 20 | "severity": 2, 21 | "line": 22, 22 | "column": 14, 23 | "endLine": 22, 24 | "endColumn": 36 25 | }, 26 | { 27 | "ruleId": "@typescript-eslint/no-unsafe-member-access", 28 | "severity": 2, 29 | "line": 24, 30 | "column": 14, 31 | "endLine": 24, 32 | "endColumn": 36 33 | }, 34 | { 35 | "ruleId": "@typescript-eslint/no-unsafe-member-access", 36 | "severity": 2, 37 | "line": 26, 38 | "column": 14, 39 | "endLine": 26, 40 | "endColumn": 36 41 | }, 42 | { 43 | "ruleId": "@typescript-eslint/no-unsafe-member-access", 44 | "severity": 2, 45 | "line": 28, 46 | "column": 14, 47 | "endLine": 28, 48 | "endColumn": 37 49 | }, 50 | { 51 | "ruleId": "@typescript-eslint/no-unsafe-member-access", 52 | "severity": 2, 53 | "line": 32, 54 | "column": 2, 55 | "endLine": 32, 56 | "endColumn": 23 57 | }, 58 | { 59 | "ruleId": "@typescript-eslint/no-unsafe-member-access", 60 | "severity": 2, 61 | "line": 34, 62 | "column": 2, 63 | "endLine": 34, 64 | "endColumn": 24 65 | }, 66 | { 67 | "ruleId": "@typescript-eslint/no-unsafe-member-access", 68 | "severity": 2, 69 | "line": 36, 70 | "column": 2, 71 | "endLine": 36, 72 | "endColumn": 24 73 | }, 74 | { 75 | "ruleId": "@typescript-eslint/no-unsafe-member-access", 76 | "severity": 2, 77 | "line": 38, 78 | "column": 2, 79 | "endLine": 38, 80 | "endColumn": 24 81 | }, 82 | { 83 | "ruleId": "@typescript-eslint/no-unsafe-member-access", 84 | "severity": 2, 85 | "line": 40, 86 | "column": 2, 87 | "endLine": 40, 88 | "endColumn": 25 89 | } 90 | ] -------------------------------------------------------------------------------- /test/samples/typescript-unsafe-member-access/external-file.ts: -------------------------------------------------------------------------------- 1 | export const external_safe = ['hi']; 2 | export const external_unsafe: any = null; 3 | -------------------------------------------------------------------------------- /test/samples/typescript-unsafe-member-access/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "include": ["**/*"] 3 | } 4 | -------------------------------------------------------------------------------- /test/samples/typescript/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | parser: '@typescript-eslint/parser', 3 | extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'], 4 | plugins: ['@typescript-eslint'], 5 | settings: { 6 | 'svelte3/typescript': require('typescript'), 7 | }, 8 | rules: { 9 | indent: ['error', 'tab'], 10 | semi: 'error', 11 | }, 12 | }; 13 | -------------------------------------------------------------------------------- /test/samples/typescript/Input.svelte: -------------------------------------------------------------------------------- 1 | 5 | 6 | 21 | 22 | {b} 23 |

{x}

24 | -------------------------------------------------------------------------------- /test/samples/typescript/expected.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "ruleId": "module-script-reactive-declaration", 4 | "severity": 1, 5 | "line": 3, 6 | "column": 2, 7 | "endLine": 3, 8 | "endColumn": 12 9 | }, 10 | { 11 | "ruleId": "no-undef", 12 | "severity": 2, 13 | "line": 3, 14 | "column": 5, 15 | "endLine": 3, 16 | "endColumn": 7 17 | }, 18 | { 19 | "ruleId": "unused-export-let", 20 | "severity": 1, 21 | "line": 7, 22 | "column": 13, 23 | "endLine": 7, 24 | "endColumn": 19 25 | }, 26 | { 27 | "ruleId": "@typescript-eslint/no-explicit-any", 28 | "severity": 1, 29 | "line": 7, 30 | "column": 16, 31 | "endLine": 7, 32 | "endColumn": 19, 33 | "suggestions": [ 34 | { 35 | "messageId": "suggestUnknown", 36 | "fix": { 37 | "range": [ 38 | 58, 39 | 61 40 | ], 41 | "text": "unknown" 42 | }, 43 | "desc": "Use `unknown` instead, this will force you to explicitly, and safely assert the type is correct." 44 | }, 45 | { 46 | "messageId": "suggestNever", 47 | "fix": { 48 | "range": [ 49 | 58, 50 | 61 51 | ], 52 | "text": "never" 53 | }, 54 | "desc": "Use `never` instead, this is useful when instantiating generic type parameters that you don't need to know the type of." 55 | } 56 | ] 57 | }, 58 | { 59 | "ruleId": "indent", 60 | "severity": 2, 61 | "line": 9, 62 | "column": 2, 63 | "endLine": 9, 64 | "endColumn": 3, 65 | "fix": { 66 | "range": [ 67 | 112, 68 | 113 69 | ], 70 | "text": "" 71 | } 72 | }, 73 | { 74 | "ruleId": "@typescript-eslint/no-explicit-any", 75 | "severity": 1, 76 | "line": 9, 77 | "column": 17, 78 | "endLine": 9, 79 | "endColumn": 20, 80 | "suggestions": [ 81 | { 82 | "messageId": "suggestUnknown", 83 | "fix": { 84 | "range": [ 85 | 79, 86 | 82 87 | ], 88 | "text": "unknown" 89 | }, 90 | "desc": "Use `unknown` instead, this will force you to explicitly, and safely assert the type is correct." 91 | }, 92 | { 93 | "messageId": "suggestNever", 94 | "fix": { 95 | "range": [ 96 | 79, 97 | 82 98 | ], 99 | "text": "never" 100 | }, 101 | "desc": "Use `never` instead, this is useful when instantiating generic type parameters that you don't need to know the type of." 102 | } 103 | ] 104 | }, 105 | { 106 | "ruleId": "semi", 107 | "severity": 2, 108 | "line": 9, 109 | "column": 20, 110 | "endLine": 10, 111 | "endColumn": 2, 112 | "fix": { 113 | "range": [ 114 | 130, 115 | 130 116 | ], 117 | "text": ";" 118 | } 119 | }, 120 | { 121 | "ruleId": "@typescript-eslint/no-unused-vars", 122 | "severity": 1, 123 | "line": 12, 124 | "column": 8, 125 | "endLine": 12, 126 | "endColumn": 11 127 | }, 128 | { 129 | "ruleId": "@typescript-eslint/no-empty-interface", 130 | "severity": 2, 131 | "line": 14, 132 | "column": 12, 133 | "endLine": 14, 134 | "endColumn": 13 135 | }, 136 | { 137 | "ruleId": "@typescript-eslint/no-unused-vars", 138 | "severity": 1, 139 | "line": 14, 140 | "column": 12, 141 | "endLine": 14, 142 | "endColumn": 13 143 | }, 144 | { 145 | "ruleId": "@typescript-eslint/no-unused-vars", 146 | "severity": 1, 147 | "line": 16, 148 | "column": 13, 149 | "endLine": 16, 150 | "endColumn": 14 151 | }, 152 | { 153 | "ruleId": "@typescript-eslint/no-empty-function", 154 | "severity": 2, 155 | "line": 16, 156 | "column": 16, 157 | "endLine": 16, 158 | "endColumn": 18 159 | }, 160 | { 161 | "ruleId": "missing-declaration", 162 | "severity": 1, 163 | "line": 23, 164 | "column": 5, 165 | "endLine": 23, 166 | "endColumn": 6 167 | }, 168 | { 169 | "ruleId": "no-undef", 170 | "severity": 2, 171 | "line": 23, 172 | "column": 5, 173 | "endLine": 23, 174 | "endColumn": 6 175 | } 176 | ] 177 | -------------------------------------------------------------------------------- /test/samples/unused-write-only-store/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | rules: { 3 | "no-unused-vars": "error", 4 | }, 5 | }; 6 | -------------------------------------------------------------------------------- /test/samples/unused-write-only-store/Input.svelte: -------------------------------------------------------------------------------- 1 | 12 |
$imported = 'clicked' } on:keyup={() => $imported = 'clicked' } /> 13 | -------------------------------------------------------------------------------- /test/samples/unused-write-only-store/expected.json: -------------------------------------------------------------------------------- 1 | [] 2 | --------------------------------------------------------------------------------