UNPKG

1.18 kBJavaScriptView Raw
1const { multilineFixer } = require('./es-beautifier-common.js');
2
3const create = (context) => {
4 const option = context.options[0] || {
5 allowSingleLine: true,
6 maxSpecifiersInSingleLine: 3,
7 maxLenInSingleLine: 80,
8 };
9 const allowSingleLine = option.allowSingleLine;
10 const maxChildren = option.maxSpecifiersInSingleLine;
11 const maxLen = option.maxLenInSingleLine;
12
13 const sourceCode = context.getSourceCode();
14
15 const enterImportDeclaration = multilineFixer({
16 allowSingleLine,
17 maxChildren,
18 maxLen,
19 context,
20 sourceCode,
21 childrenName: 'specifiers',
22 message: 'Specifiers in an import should be on a new line.',
23 });
24
25 return { ImportDeclaration: enterImportDeclaration };
26};
27
28module.exports = {
29 meta: {
30 docs: {
31 description: 'enforce multi-line specifiers in an import',
32 category: 'Stylistic Issues',
33 },
34 fixable: 'whitespace',
35 schema: [{
36 type: 'object',
37 properties: {
38 allowSingleLine: { type: 'boolean' },
39 maxSpecifiersInSingleLine: { type: 'integer' },
40 maxLenInSingleLine: { type: 'integer' },
41 },
42 additionalProperties: false,
43 }],
44 },
45 create,
46};