Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
353 views
in Technique[技术] by (71.8m points)

javascript - eslint throwing errors where there are no errors

I’m receiving the following errors when running yarn eslint:

/…/src/a.js
  4:1   error  Expected indentation of 1 tab but found 2 spaces   indent
  4:43  error  Strings must use singlequote                       quotes
  5:1   error  Expected indentation of 2 tabs but found 4 spaces  indent
  6:1   error  Expected indentation of 1 tab but found 2 spaces   indent
  6:6   error  Strings must use singlequote                       quotes

? 5 problems (5 errors, 0 warnings)
  5 errors and 0 warnings potentially fixable with the `--fix` option.

This is my .eslintrc.js file:

module.exports = {
    env: {
        browser: true,
        es2021: true,
    },
    extends: [
        'eslint:recommended',
        'plugin:react/recommended',
    ],
    parserOptions: {
        ecmaFeatures: { jsx: true },
        ecmaVersion: 12,
        sourceType: 'module',
    },
    plugins: ['react'],
    settings: {
        react: { version: 'detect' },
    },
    rules: {
        indent: [
            'error',
            'tab'
        ],
        'linebreak-style': [
            'error',
            'unix',
        ],
        quotes: [
            'error',
            'single'
        ],
        semi: [
            'error',
            'always'
        ]
    }
};

… and the file in question:

import React from "react";
import { css } from "./a.css";

export function App() {
return (
<div className={css.App}>
Hello.
</div>
);
}

Note: I include here to denote tabs as Stack Overflow replaces actual tabs with 4 spaces.

None of the errors reported by eslint are actual errors in the file. All indents are correct, and I only use single quotes. Hell, there isn’t even a line 43 in that file, as eslint is reporting.

What might be happening here?

question from:https://stackoverflow.com/questions/65924598/eslint-throwing-errors-where-there-are-no-errors

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
indent: [
        'error',
        'tab'
    ],
quotes: [
        'error',
        'single'
    ],

This rule in you eslint tell that you shall not use space but a tab Key for indentation either remove this rule OR on the lines where the INDENT error has occured you shall find space used for indentation remove them and use the Tab key Also for the Quote Error check you variable for the string values saved using single quote, if you are using vscode then you might need to remove this rule or update the vscode setting and prevent it from updating the single quote to double quote while auto saving


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...