简体   繁体   English

如何在 svelte 项目中配置 sass 和 ESLint?

[英]How to configure sass and ESLint in svelte project?

I am new in svelte.我是新来的苗条。 I trying to add ESLint to my svelte project.我试图将 ESLint 添加到我的苗条项目中。 My eslintrc.json:我的 eslintrc.json:

{
  "env": {
    "es6": true,
    "browser": true,
    "node": true
  },
  "extends": [
    "standard", "airbnb-base/legacy"
  ],
  "plugins": [
    "svelte3"
  ],
  "overrides": [
    {
      "files": ["**/*.svelte"],
      "processor": "svelte3/svelte3"
    }
  ],
  "parser": "babel-eslint",
  "parserOptions": {
    "ecmaVersion": 2019,
    "sourceType": "module"
  }
} 

It works, but linter rules does not support sass syntax.它有效,但 linter 规则不支持 sass 语法。 I have this error.我有这个错误。 在此处输入图片说明

How can I fix it?我该如何解决?

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.如果您在组件样式上使用某种预处理器,那么当此插件在您的组件上调用 Svelte 编译器时,它很可能会抛出异常。 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.然而,在当前的现实中,您可以简单地忽略使用标准 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.您不会从 linter 收到有关样式的警告,但您的应用程序仍将使用它们(当然)并且编译器警告仍将出现在您的构建日志中。

This setting can be given a function that accepts an object of attributes on a tag (like that passed to a Svelte preprocessor) and returns whether to ignore the style block for the purposes of linting.可以为该设置提供一个函数,该函数接受标签上的属性对象(如传递给 Svelte 预处理器的对象)并返回是否出于 linting 的目的而忽略样式块。

The default is to not ignore any styles.默认是不忽略任何样式。

 settings: {
    'svelte3/ignore-styles': () => true
  }

I faced the same issue and there is no documentation on how to use the svelte3/ignore-styles in settings to ignore the styles in eslint.我遇到了同样的问题,并且没有关于如何在设置中使用svelte3/ignore-styles来忽略 eslint 中的样式的文档。 Here is how i fixed the issue -这是我解决问题的方法 -

I Changed .eslintrc to .eslintrc.js in order to use the ignore rule as a function -我将 .eslintrc 更改为 .eslintrc.js 以便将忽略规则用作函数 -

module.exports = {
    ...
    
    "rules" : {

    },

    "settings": {
      "svelte3/ignore-styles": () => true
    }

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM