javascript - 在 css 中通过 Eslint 提交时出现错误

标签 javascript css reactjs eslint stylelint

我在 GIT 上提交代码时遇到错误。我正在使用 ESLINT 和 Stylelint 进行设置。我写了简单的 css,但出现错误。在第一行和第一列获取问题

2:1  error  Parsing error: Unexpected token

1 | /* Form elements style */
> 2 | .flex-wrapper {
  | ^
3 |     display: flex;
4 |     flex-wrap: wrap;
5 |     margin: 0px -20px;

✖ 1 problem (1 error, 0 warnings)
husky > pre-commit hook failed (add --no-verify to bypass)

`/* Form elements style */
.flex-wrapper {
    display: flex;
    flex-wrap: wrap;
    margin: 0px -20px;
}`

.stylelintrc

    {
  "extends": "stylelint-config-recommended"
}

lint-staged.config.js

module.exports = {
  linters: {
    '**/*.+(js|jsx|md|css|yml|yaml|scss)': [
      './node_modules/.bin/eslint --fix',
      './node_modules/.bin/stylelint *.css --fix',
      './node_modules/.bin/prettier --write',
      'git add',
    ],
  },
  ignore: ['node_modules', 'package.json', 'package-lock.json'],
};

.eslintrc.js

module.exports = {
  extends: ['airbnb', 'prettier', 'prettier/react'],
  plugins: ['markdown'],
  parser: 'babel-eslint',
  env: {
    browser: true,
    jest: true,
  },
  rules: {
    'react/button-has-type': 0,
    'react/require-default-props': 0,
    'import/named': 0,
    camelcase: 0,
    'react/destructuring-assignment': 1,
  },
};

最佳答案

lint-staged.config.js 文件有问题

module.exports = {
  linters: {
    '**/*.+(js|jsx|md|yml|yaml)': [
      './node_modules/.bin/eslint --fix',
      './node_modules/.bin/prettier --write',
      'git add',
    ],
    '**/*.+(css|scss)': [
      './node_modules/.bin/stylelint *.css --fix',
      './node_modules/.bin/prettier --write',
      'git add',
    ],
  },
  ignore: ['node_modules', 'package.json', 'package-lock.json'],
};

现在一切正常

关于javascript - 在 css 中通过 Eslint 提交时出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55804113/

相关文章:

javascript - 使用 WinMove 移动时使可拖动面板为 'sticky'

html - Div 不会在 IE8 中占浏览器的 100% 宽度

reactjs - 创建快照时 Jest/Enzyme ShallowWrapper 为空

html - 如何在使用 translateX() 在 slider 中设置动画时完全隐藏之前的图像?

css - 在左侧对齐左元素,在右侧对齐右元素

reactjs - 如何在ReactJS中通过组件名称获取元素

javascript - 无法读取未定义的属性 - RENDER(输入)

javascript - 正则表达式获取包含点的代码之间的字符串

javascript - 为什么我的组件没有在状态更改时重新渲染?

javascript - 如何以编程方式获取 json 对象列表的属性?