sveltejs / eslint-plugin-svelte3

An ESLint plugin for Svelte v3 components.
MIT License
373 stars 43 forks source link

Cannot read property 'filter' of undefined #9

Closed RikuVan closed 5 years ago

RikuVan commented 5 years ago

I am getting this error (trace below). I thought this was perhaps due to using the typescript parser but it seems to occur even if I remove the parser. Any suggestions would be much appreciated about how to proceed/ debug the issue.

eslintrc:

{
  "parser": "@typescript-eslint/parser",
  "plugins": ["svelte3", "@typescript-eslint"],
  "extends": "standard",
  "parserOptions": {
    "extraFileExtensions": [".svelte"]
  },
  "rules": {
    "semis": 0,
    "space-before-function-paren": 0,
    "no-console": "off"
  }
}
TypeError: Cannot read property 'filter' of undefined
    at preprocess (/Users/richard.vancamp/Code/Repos/svelte-ts-starter/node_modules/eslint-plugin-svelte3/index.js:157:30)
    at Linter.verify (/Users/richard.vancamp/Code/Repos/svelte-ts-starter/node_modules/eslint/lib/linter.js:954:13)
    at Linter.verify (/Users/richard.vancamp/Code/Repos/svelte-ts-starter/node_modules/eslint-plugin-svelte3/index.js:303:17)
    at Linter.verifyAndFix (/Users/richard.vancamp/Code/Repos/svelte-ts-starter/node_modules/eslint/lib/linter.js:1047:29)
    at processText (/Users/richard.vancamp/Code/Repos/svelte-ts-starter/node_modules/eslint/lib/cli-engine.js:197:32)
    at processFile (/Users/richard.vancamp/Code/Repos/svelte-ts-starter/node_modules/eslint/lib/cli-engine.js:241:12)
    at fileList.map.fileInfo (/Users/richard.vancamp/Code/Repos/svelte-ts-starter/node_modules/eslint/lib/cli-engine.js:616:40)
    at Array.map (<anonymous>)
    at CLIEngine.executeOnFiles (/Users/richard.vancamp/Code/Repos/svelte-ts-starter/node_modules/eslint/lib/cli-engine.js:588:34)
    at Object.execute (/Users/richard.vancamp/Code/Repos/svelte-ts-starter/node_modules/eslint/lib/cli.js:205:111)
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
➜  svelte-ts-starter git:(master) ✗ yarn run lint
yarn run v1.13.0
$ eslint src/**/*.ts src/**/*.svelte
<script>
  export let src =
    'https://images.pexels.com/photos/356378/pexels-photo-356378.jpeg?auto=compress&cs=tinysrgb&dpr=2&w=500'
  export let alt = 'white-dog'
</script>

<img
  src="https://images.pexels.com/photos/356378/pexels-photo-356378.jpeg?auto=compress&cs=tinysrgb&dpr=2&w=500"
  alt="hey"
/>

TypeError: Cannot read property 'filter' of undefined
    at preprocess (/Users/richard.vancamp/Code/Repos/svelte-ts-starter/node_modules/eslint-plugin-svelte3/index.js:157:30)
    at Linter.verify (/Users/richard.vancamp/Code/Repos/svelte-ts-starter/node_modules/eslint/lib/linter.js:954:13)
    at Linter.verify (/Users/richard.vancamp/Code/Repos/svelte-ts-starter/node_modules/eslint-plugin-svelte3/index.js:303:17)
    at Linter.verifyAndFix (/Users/richard.vancamp/Code/Repos/svelte-ts-starter/node_modules/eslint/lib/linter.js:1047:29)
    at processText (/Users/richard.vancamp/Code/Repos/svelte-ts-starter/node_modules/eslint/lib/cli-engine.js:197:32)
    at processFile (/Users/richard.vancamp/Code/Repos/svelte-ts-starter/node_modules/eslint/lib/cli-engine.js:241:12)
    at fileList.map.fileInfo (/Users/richard.vancamp/Code/Repos/svelte-ts-starter/node_modules/eslint/lib/cli-engine.js:616:40)
    at Array.map (<anonymous>)
    at CLIEngine.executeOnFiles (/Users/richard.vancamp/Code/Repos/svelte-ts-starter/node_modules/eslint/lib/cli-engine.js:588:34)
    at Object.execute (/Users/richard.vancamp/Code/Repos/svelte-ts-starter/node_modules/eslint/lib/cli.js:205:111)
RikuVan commented 5 years ago

By the way, it would be super helpful if you could provide an example of how the options, like ignoring styles, are actually used with the .eslintrc.

Conduitry commented 5 years ago

I can't reproduce this. I have a package.json containing:

{
  "dependencies": {
    "@typescript-eslint/eslint-plugin": "^1.7.0",
    "@typescript-eslint/parser": "^1.7.0",
    "eslint": "^5.16.0",
    "eslint-config-standard": "^12.0.0",
    "eslint-plugin-import": "^2.17.2",
    "eslint-plugin-node": "^8.0.1",
    "eslint-plugin-promise": "^4.1.1",
    "eslint-plugin-standard": "^4.0.0",
    "eslint-plugin-svelte3": "^1.0.0",
    "svelte": "^3.1.0",
    "typescript": "^3.4.5"
  }
}

a .eslintrc containining:

{
  "root": true,
  "parser": "@typescript-eslint/parser",
  "plugins": ["svelte3", "@typescript-eslint"],
  "extends": "standard",
  "parserOptions": {
    "extraFileExtensions": [".svelte"]
  },
  "rules": {
    "semis": 0,
    "space-before-function-paren": 0,
    "no-console": "off"
  }
}

and a test.svelte containing:

<script>
  export let src =
    'https://images.pexels.com/photos/356378/pexels-photo-356378.jpeg?auto=compress&cs=tinysrgb&dpr=2&w=500'
  export let alt = 'white-dog'
</script>

<img
  src="https://images.pexels.com/photos/356378/pexels-photo-356378.jpeg?auto=compress&cs=tinysrgb&dpr=2&w=500"
  alt="hey"
/>

and when I run ./node_modules/.bin/eslint test.svelte I get no errors. If I edit the file to introduce a linting error (e.g., adding a semicolon), I do see that error.

Do you have a repo where I can reproduce this issue?

RikuVan commented 5 years ago

https://github.com/RikuVan/svelte3-ts-starter

RikuVan commented 5 years ago

I can try later to put the code on online somewhere, e.g. codesandbox or glitch.

Conduitry commented 5 years ago

When I clone that project, install dependencies, and run the lint script I get:

/.../svelte3-ts-starter/src/components/Image.svelte
  2:2  error  Parsing error: Expression expected

✖ 1 problem (1 error, 0 warnings)
RikuVan commented 5 years ago

sorry that was probably was slightly different than the version I had locally, which I now pushed--namely the linting was removed.

RikuVan commented 5 years ago

Anyways, if you don't get a similar issue, then I should do something in Glitch so we know it is not some other environment issue. node v11.10.0 by the way.

Conduitry commented 5 years ago

Okay, thanks, yep I am seeing the same exception as you are now.

Conduitry commented 5 years ago

https://github.com/RikuVan/svelte3-ts-starter/blob/master/yarn.lock#L2710 You're running Svelte 3 beta 3. Beta 4 introduced some changes to the output of the compiler that this plugin needs. You need to upgrade to a newer version, preferably one of the official non-beta releases from this past week.

RikuVan commented 5 years ago

oh no, sorry to trouble you with old version. Works now of course.