UNPKG

1.14 kBJavaScriptView Raw
1const { multilineFixer } = require('./es-beautifier-common.js');
2
3const create = (context) => {
4 const option = context.options[0] || {};
5 const allowSingleLine = option.allowSingleLine;
6 const maxChildren = option.maxStatementsInSingleLine;
7 const maxLen = option.maxLenInSingleLine;
8
9 const sourceCode = context.getSourceCode();
10
11 const enterBlockStatement = multilineFixer({
12 allowSingleLine,
13 maxChildren,
14 maxLen,
15 context,
16 sourceCode,
17 childrenName: 'body',
18 message: 'Statement in a block must be on a new line.',
19 });
20
21 return {
22 BlockStatement: enterBlockStatement,
23 Program: enterBlockStatement, // we reuse this rule for probram
24 };
25};
26
27module.exports = {
28 meta: {
29 docs: {
30 description: 'enforce multi-line statements in a block',
31 category: 'Stylistic Issues',
32 },
33 fixable: 'whitespace',
34 schema: [{
35 type: 'object',
36 properties: {
37 allowSingleLine: { type: 'boolean' },
38 maxStatementsInSingleLine: { type: 'integer' },
39 maxLenInSingleLine: { type: 'integer' },
40 },
41 additionalProperties: false,
42 }],
43 },
44 create,
45};