I want ESLint to avoid errors with special indentation

Asked 1 years ago, Updated 1 years ago, 38 views

Hello.

I want to deal with JavaScript var hoisting issue
I'm going to write the variable declaration in var at the beginning as much as possible.

Also, we often comment out variables during development, so
I'm thinking of writing like this.
A comma always appears at the end of the line.

var test01=function(){
  var
    a,
    B,
    c,
  variable;

  // Processing

};

I don't think the unused variable variable will be popular with everyone, but
Please understand that it is my rule.


when ESLint handles this. Of course, the number of indents doesn't match.
You get the error

Now create an ESLint rule and only the varend line
I'd like to exclude
I didn't know how to do it.

I don't mind if it's a helpful URL.
I would appreciate it if you could let me know.

I am using it in this library.

stsLib.js/.eslintrc.js at master ·standard-software/stsLib.js
https://github.com/standard-software/stsLib.js/blob/master/Source/stsLib.js/.eslintrc.js

I only understand how to use ESLint to create this file.

If you know, please let me know.
I look forward to your kind cooperation.

Rio.irikami taught me how to write eslint-disable-line in a comment on a specific line of the source, and I was able to confirm its operation.Thank you.

Furthermore, my ideal is not to write a comment on the source code side, but
I'd like to write the settings to .eslintrc.js, and I think it would be better if there was a way to disable-line for patterns containing specific words.
If you know how to do this, please let me know.

I also looked for a way not to indent check only the var part, but
I don't think so either.

In addition to your own writing style, if you write in the following ways:
I think there are situations where you don't want to check indentation on eslint.
Is it possible to exclude this kind of thing?

var
  a1,
  a2,
  a3,
    b1,
    b2,
    b3;

javascript

2022-09-30 21:25

1 Answers

A common way to exclude some source code from eslint is to Disabling Rules with Inline Comments, which is described in Configuring ESLint.Specifically, you can write a comment in the source code that instructs you to skip lint.

As for the code in the question, a single line skip at the end of the line //eslint-disable-line would be appropriate.

There are many other ways to write it, so please refer to the document above for more information.

Regarding the style, I'm a snake-footed person...

  • const/let is valid instead of var.The variable declaration at the beginning of the block may have been influenced by old C, but at least it is meaningless except for ethical significance in js.It is safer to declare with const/let as appropriate at the required scope.
  • If you know that variables are often commented out during development, In the first place, you should stop declaring variables using the comma operator (with var/let/const respectively).I can't think of any merit in adopting your proposed notation.

These are some kind of subjective opinion and are not the main idea of the question, so please refer to them only.


2022-09-30 21:25

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.