question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ClassDeclaration/ClassExpression option for the indent rule

See original GitHub issue

Tell us about your environment

  • ESLint Version: v3.17.1 (using the indent-rewrite branch)
  • Node Version: v7.7.2
  • npm Version: v4.1.2

What parser (default, Babel-ESLint, etc.) are you using? default

Please show your full configuration:

module.exports = {
    root: true,
    parserOptions: {
        ecmaVersion: 8
    },
    rules: {
        indent: [2, 2, {
            SwitchCase: 2,
            VariableDeclarator: 2,
            outerIIFEBody: 2,
            MemberExpression: 2,
            FunctionDeclaration: {
                parameters: 2,
                body: 2
            },
            FunctionExpression: {
                parameters: 2,
                body: 2
            },
            CallExpression: {
                arguments: 2
            },
            ArrayExpression: 2,
            ObjectExpression: 2
        }]
    }
};

What did you do? Please include the actual source code causing the issue.

class a {
    m() {
        "hmm";
    }
}
let b = class {
    m() {
        "hmm";
    }
};

What did you expect to happen? There should be an option to set the indentation for ClassDeclaration and ClassExpression.

What actually happened? Please include the actual, raw output from ESLint.

c:\nodejs\test\test.js
  2:5  error  Expected indentation of 2 spaces but found 4  indent
  3:9  error  Expected indentation of 6 spaces but found 8  indent
  4:5  error  Expected indentation of 2 spaces but found 4  indent
  7:5  error  Expected indentation of 2 spaces but found 4  indent
  8:9  error  Expected indentation of 6 spaces but found 8  indent
  9:5  error  Expected indentation of 2 spaces but found 4  indent

✖ 6 problems (6 errors, 0 warnings)

$ eslint test.js --fix Lints to:

class a {
  m() {
      "hmm";
  }
}
let b = class {
  m() {
      "hmm";
  }
};

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
not-an-aardvarkcommented, Oct 30, 2017

It would be better to depend on lodash, ast-utils, and functional-red-black-tree directly in your plugin rather than loading ESLint’s versions of the modules at runtime. That way, your plugin won’t break if ESLint modifies its dependencies or helper functions in a future release.

0reactions
nemoxpscommented, Oct 30, 2017

@mqklin That error is caused by this line: const lodash = require('../../eslint/node_modules/lodash'); To explain this line: I’m assuming that ESLint and my plugin both are installed globally. It is in my case and it just works fine. If you need it to work locally, just fill an issue and I’m going to fix it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

class expression - JavaScript - MDN Web Docs - Mozilla
The class keyword can be used to define a class inside an expression. Similar to function expressions, class expressions can be named or...
Read more >
Rules - JavaScript Standard Style
Use 2 spaces for indentation. eslint: indent · Use single quotes for strings except to avoid escaping. eslint: quotes · No unused variables....
Read more >
Optional Braces - Scala 3 - EPFL
Scala 3 enforces some rules on indentation and allows some occurrences of braces {. ... of a class, trait, or object that are...
Read more >
indent - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
indent | typescript-eslint
indent. danger. We strongly recommend you do not use this rule or any other formatting linter rules. Use ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found