UNPKG

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