🔧 The --fix
option on the command line can automatically fix some of the problems reported by this rule.
We want clear rules on how destructured import specifiers are broken up by lines.
This rule has a mixed option:
For example, to enforce multiline behavior (default):
{
"indent": ["error", "multiline", 2]
}
or use the default:
{
"indent": ["error"]
}
Or to enforce a specifier limit:
{
"indent": ["error", 3, 2]
}
Both options support a second options argument to determine how many spaces of indentation to use. This is necessary because as of eslint 3, indent
will not enforce indentation of import
statements.
Using multiline enforcement means that you have two options:
- Use line breaks between no specifiers
- Use line breaks between all specifiers
👎 Examples of incorrect code for this rule with the "multiline", 2
option:
// eslint import-destructuring-spacing: ["error", "multiline", 2]
import {
a, b,
c
} from 'somewhere';
// eslint import-destructuring-spacing: ["error", "multiline", 2]
import {
a, b,
c
} from 'somewhere';
// eslint import-destructuring-spacing: ["error", "multiline", 2]
import { a, b, c
} from 'somewhere';
// eslint import-destructuring-spacing: ["error", "multiline", 2]
import {
a, b, c } from 'somewhere';
👍 Examples of correct code for this rule with the "multiline"
option:
// eslint import-destructuring-spacing: ["error", "multiline", 2]
import { a, b, c } from 'somewhere';
// eslint import-destructuring-spacing: ["error", "multiline", 2]
import { a, b, c }
from 'somewhere';
// eslint import-destructuring-spacing: ["error", "multiline", 2]
import {
a,
b,
c
} from 'somewhere';
// eslint import-destructuring-spacing: ["error", "multiline", 2]
import {
a,
b,
c
}
from 'somewhere';
Using a specifier limit means that for this number or greater specifier, you must use separate lines for all of them. If you have less than this many, you must put them on a single line.
👎 Examples of incorrect code for this rule with the 3, 2
option (specifier limit of 3
with indentation of 2
spaces):
// eslint import-destructuring-spacing: ["error", 3, 2]
import { a, b, c } from 'somewhere';
// eslint import-destructuring-spacing: ["error", 3, 2]
import {
a,
b
} from 'somewhere';
// eslint import-destructuring-spacing: ["error", 3, 2]
import {
a,
b,
c
} from 'somewhere';
// eslint import-destructuring-spacing: ["error", 3, 2]
import { a, b, c, d } from 'somewhere';
👍 Examples of correct code for this rule with the 3, 2
option (specifier limit of 3
with indentation of 2
spaces):
// eslint import-destructuring-spacing: ["error", 3, 2]
import { a, b } from 'somewhere';
// eslint import-destructuring-spacing: ["error", 3, 2]
import { a, b }
from 'somewhere';
// eslint import-destructuring-spacing: ["error", 3, 2]
import {
a,
b,
c
} from 'somewhere';
// eslint import-destructuring-spacing: ["error", 3, 2]
import {
a,
b,
c
}
from 'somewhere';
// eslint import-destructuring-spacing: ["error", 3, 2]
import {
a,
b,
c,
d
} from 'somewhere';
// eslint import-destructuring-spacing: ["error", 3, 2]
import {
a,
b,
c,
d
}
from 'somewhere';
If you don't want to enforce line breaks in import speecifiers