From 2006336b48243accc81d2c743c782b54d6e91cac Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Fri, 15 Mar 2019 01:50:56 +0800 Subject: [PATCH 1/5] autofix for 'sort-styles' rule --- lib/rules/sort-styles.js | 60 +++++++-- lib/util/stylesheet.js | 56 +++++++-- tests/lib/rules/sort-styles.js | 223 ++++++++++++++++++++++++++------- 3 files changed, 275 insertions(+), 64 deletions(-) diff --git a/lib/rules/sort-styles.js b/lib/rules/sort-styles.js index 3f2da77..bfc46ce 100644 --- a/lib/rules/sort-styles.js +++ b/lib/rules/sort-styles.js @@ -12,7 +12,8 @@ const { astHelpers } = require('../util/stylesheet'); const { - getStyleDeclarations, + getStyleDeclarationsChunks, + getPropertiesChunks, getStylePropertyIdentifier, isStyleSheetDeclaration, } = astHelpers; @@ -28,13 +29,41 @@ module.exports = (context) => { const ignoreStyleProperties = options.ignoreStyleProperties; const isValidOrder = order === 'asc' ? (a, b) => a <= b : (a, b) => a >= b; - function report(type, node, prev, current) { + const sourceCode = context.getSourceCode(); + + function sort(array) { + return [].concat(array).sort((a, b) => { + const identifierA = getStylePropertyIdentifier(a); + const identifierB = getStylePropertyIdentifier(b); + + let sortOrder = 0; + if (identifierA < identifierB) { + sortOrder = -1; + } else if (identifierA > identifierB) { + sortOrder = 1; + } + return sortOrder * (order === 'asc' ? 1 : -1); + }); + } + + function report(array, type, node, prev, current) { const currentName = getStylePropertyIdentifier(current); const prevName = getStylePropertyIdentifier(prev); context.report({ node, message: `Expected ${type} to be in ${order}ending order. '${currentName}' should be before '${prevName}'.`, loc: current.key.loc, + fix(fixer) { + const sortedArray = sort(array); + return array + .map((item, i) => { + if (item !== sortedArray[i]) { + return fixer.replaceText(item, sourceCode.getText(sortedArray[i])); + } + return null; + }) + .filter(Boolean); + }, }); } @@ -51,7 +80,7 @@ module.exports = (context) => { const currentName = getStylePropertyIdentifier(current); if (!isValidOrder(prevName, currentName)) { - return report(arrayName, node, previous, current); + return report(array, arrayName, node, previous, current); } } } @@ -62,26 +91,33 @@ module.exports = (context) => { return; } - const classDefinitions = getStyleDeclarations(node); + const classDefinitionsChunks = getStyleDeclarationsChunks(node); if (!ignoreClassNames) { - checkIsSorted(classDefinitions, 'class names', node); + classDefinitionsChunks.forEach((classDefinitions) => { + checkIsSorted(classDefinitions, 'class names', node); + }); } if (ignoreStyleProperties) return; - classDefinitions.forEach((classDefinition) => { - const styleProperties = classDefinition.value.properties; - if (!styleProperties || styleProperties.length < 2) { - return; - } - - checkIsSorted(styleProperties, 'style properties', node); + classDefinitionsChunks.forEach((classDefinitions) => { + classDefinitions.forEach((classDefinition) => { + const styleProperties = classDefinition.value.properties; + if (!styleProperties || styleProperties.length < 2) { + return; + } + const stylePropertyChunks = getPropertiesChunks(styleProperties); + stylePropertyChunks.forEach((stylePropertyChunk) => { + checkIsSorted(stylePropertyChunk, 'style properties', node); + }); + }); }); }, }; }; +module.exports.fixable = 'code'; module.exports.schema = [ { enum: ['asc', 'desc'], diff --git a/lib/util/stylesheet.js b/lib/util/stylesheet.js index 21bf520..051b384 100644 --- a/lib/util/stylesheet.js +++ b/lib/util/stylesheet.js @@ -127,15 +127,26 @@ const astHelpers = { }, getStyleSheetName: function (node) { + if (node && node.id) { + return node.id.name; + } + }, + + getStyleDeclarations: function (node) { if ( node && - node.id + node.init && + node.init.arguments && + node.init.arguments[0] && + node.init.arguments[0].properties ) { - return node.id.name; + return node.init.arguments[0].properties.filter(property => property.type === 'Property'); } + + return []; }, - getStyleDeclarations: function (node) { + getStyleDeclarationsChunks: function (node) { if ( node && node.init && @@ -143,16 +154,45 @@ const astHelpers = { node.init.arguments[0] && node.init.arguments[0].properties ) { - return node - .init - .arguments[0] - .properties - .filter(property => property.type === 'Property'); + const properties = node.init.arguments[0].properties; + const result = []; + let chunk = []; + for (let i = 0; i < properties.length; i += 1) { + const property = properties[i]; + if (property.type === 'Property') { + chunk.push(property); + } else if (chunk.length) { + result.push(chunk); + chunk = []; + } + } + if (chunk.length) { + result.push(chunk); + } + return result; } return []; }, + getPropertiesChunks: function (properties) { + const result = []; + let chunk = []; + for (let i = 0; i < properties.length; i += 1) { + const property = properties[i]; + if (property.type === 'Property') { + chunk.push(property); + } else if (chunk.length) { + result.push(chunk); + chunk = []; + } + } + if (chunk.length) { + result.push(chunk); + } + return result; + }, + getExpressionIdentifier: function (node) { if (node) { switch (node.type) { diff --git a/tests/lib/rules/sort-styles.js b/tests/lib/rules/sort-styles.js index 22b1e27..62bb4d6 100644 --- a/tests/lib/rules/sort-styles.js +++ b/tests/lib/rules/sort-styles.js @@ -121,73 +121,208 @@ const tests = { `, options: ['asc', { ignoreClassNames: true }], }, - ], - invalid: [ { code: ` const styles = StyleSheet.create({ - myClass: { - y: 2, - x: 1, - z: 3, - }, - }) - `, - errors: [{ - message: 'Expected style properties to be in ascending order. \'x\' should be before \'y\'.', - }], - }, - { - code: ` - const styles = StyleSheet.create({ - b: { + a: { x: 1, y: 2, + ...c, + a: 1, + c: 2, + ...g, + b: 5, }, - a: { + c: {}, + ...g, + b: { a: 1, b: 2, }, }) `, - errors: [{ - message: 'Expected class names to be in ascending order. \'a\' should be before \'b\'.', - }], }, + ], + invalid: [ { code: ` - const styles = StyleSheet.create({ - 'b': {}, - 'a': {}, - }) - `, - errors: [{ - message: 'Expected class names to be in ascending order. \'a\' should be before \'b\'.', - }], + const styles = StyleSheet.create({ + myClass: { + y: 2, + x: 1, + z: 3, + }, + }) + `, + output: ` + const styles = StyleSheet.create({ + myClass: { + x: 1, + y: 2, + z: 3, + }, + }) + `, + errors: [ + { + message: "Expected style properties to be in ascending order. 'x' should be before 'y'.", + }, + ], }, { code: ` - const styles = StyleSheet.create({ - ['b']: {}, - [\`a\`]: {}, - }) - `, - errors: [{ - message: 'Expected class names to be in ascending order. \'a\' should be before \'b\'.', - }], + const styles = StyleSheet.create({ + b: { + x: 1, + y: 2, + }, + a: { + a: 1, + b: 2, + }, + }) + `, + output: ` + const styles = StyleSheet.create({ + a: { + a: 1, + b: 2, + }, + b: { + x: 1, + y: 2, + }, + }) + `, + errors: [ + { + message: "Expected class names to be in ascending order. 'a' should be before 'b'.", + }, + ], + }, + { + code: ` + const styles = StyleSheet.create({ + 'd': {}, + 'c': {}, + 'a': {}, + 'e': {}, + 'b': {}, + }) + `, + + output: ` + const styles = StyleSheet.create({ + 'a': {}, + 'b': {}, + 'c': {}, + 'd': {}, + 'e': {}, + }) + `, + errors: [ + { + message: "Expected class names to be in ascending order. 'c' should be before 'd'.", + }, + ], + }, + { + code: ` + const styles = StyleSheet.create({ + ['b']: {}, + [\`a\`]: {}, + }) + `, + output: ` + const styles = StyleSheet.create({ + [\`a\`]: {}, + ['b']: {}, + }) + `, + errors: [ + { + message: "Expected class names to be in ascending order. 'a' should be before 'b'.", + }, + ], + }, + { + code: ` + const a = 'a'; + const b = 'b'; + const styles = StyleSheet.create({ + [\`\${a}-\${b}-b\`]: {}, + [\`a-\${b}-a\`]: {}, + }) + `, + output: ` + const a = 'a'; + const b = 'b'; + const styles = StyleSheet.create({ + [\`a-\${b}-a\`]: {}, + [\`\${a}-\${b}-b\`]: {}, + }) + `, + errors: [ + { + message: + "Expected class names to be in ascending order. 'a-b-a' should be before 'a-b-b'.", + }, + ], }, { code: ` - const a = 'a'; - const b = 'b'; const styles = StyleSheet.create({ - [\`\${a}-\${b}-b\`]: {}, - [\`a-\${b}-a\`]: {}, + a: { + y: 2, + x: 1, + ...c, + d: 3, + c: 2, + a: 1, + ...g, + b: 5, + }, + d: {}, + c: {}, + ...g, + b: { + a: 1, + b: 2, + }, + }) + `, + output: ` + const styles = StyleSheet.create({ + a: { + x: 1, + y: 2, + ...c, + a: 1, + c: 2, + d: 3, + ...g, + b: 5, + }, + c: {}, + d: {}, + ...g, + b: { + a: 1, + b: 2, + }, }) `, - errors: [{ - message: 'Expected class names to be in ascending order. \'a-b-a\' should be before \'a-b-b\'.', - }], + errors: [ + { + message: "Expected style properties to be in ascending order. 'x' should be before 'y'.", + }, + { + message: "Expected style properties to be in ascending order. 'c' should be before 'd'.", + }, + { + message: "Expected class names to be in ascending order. 'c' should be before 'd'.", + }, + ], }, ], }; From fcf8e1c562802181be099574ed080c9da65ca1bd Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Fri, 15 Mar 2019 09:10:30 +0800 Subject: [PATCH 2/5] add test case for comment order --- tests/lib/rules/sort-styles.js | 42 ++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tests/lib/rules/sort-styles.js b/tests/lib/rules/sort-styles.js index 62bb4d6..8c14c20 100644 --- a/tests/lib/rules/sort-styles.js +++ b/tests/lib/rules/sort-styles.js @@ -324,6 +324,48 @@ const tests = { }, ], }, + { + code: ` + const styles = StyleSheet.create({ + a: { + d: 4, + // comments + c: 3, + a: 1, + b: 2, + }, + d: {}, + c: {}, + // comments + b: { + a: 1, + b: 2, + }, + }) + `, + output: ` + const styles = StyleSheet.create({ + a: { + a: 1, + b: 2, + // comments + c: 3, + d: 4, + }, + // comments + b: { + a: 1, + b: 2, + }, + c: {}, + d: {}, + }) + `, + errors: [ + { message: "Expected style properties to be in ascending order. 'c' should be before 'd'." }, + { message: "Expected class names to be in ascending order. 'c' should be before 'd'." }, + ], + }, ], }; From edd135379eac69380454c9f4af79d522af817fd9 Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Fri, 15 Mar 2019 14:21:27 +0800 Subject: [PATCH 3/5] fix comments position --- lib/rules/sort-styles.js | 14 +++++- tests/lib/rules/sort-styles.js | 88 +++++++++++++++++++++++++++++++--- 2 files changed, 95 insertions(+), 7 deletions(-) diff --git a/lib/rules/sort-styles.js b/lib/rules/sort-styles.js index bfc46ce..aa39f44 100644 --- a/lib/rules/sort-styles.js +++ b/lib/rules/sort-styles.js @@ -46,6 +46,14 @@ module.exports = (context) => { }); } + function getActualRange(node) { + const range = [].concat(node.range); + range[0] = sourceCode + .getCommentsBefore(node) + .reduce((start, comment) => Math.min(start, comment.range[0]), range[0]); + return range; + } + function report(array, type, node, prev, current) { const currentName = getStylePropertyIdentifier(current); const prevName = getStylePropertyIdentifier(prev); @@ -58,7 +66,11 @@ module.exports = (context) => { return array .map((item, i) => { if (item !== sortedArray[i]) { - return fixer.replaceText(item, sourceCode.getText(sortedArray[i])); + const actualRange = getActualRange(sortedArray[i]); + return fixer.replaceTextRange( + getActualRange(item), + sourceCode.text.slice(actualRange[0], actualRange[1]) + ); } return null; }) diff --git a/tests/lib/rules/sort-styles.js b/tests/lib/rules/sort-styles.js index 8c14c20..c2f6af5 100644 --- a/tests/lib/rules/sort-styles.js +++ b/tests/lib/rules/sort-styles.js @@ -329,18 +329,19 @@ const tests = { const styles = StyleSheet.create({ a: { d: 4, - // comments + // comments 1 c: 3, a: 1, b: 2, }, d: {}, c: {}, - // comments + // comments 2 b: { a: 1, b: 2, }, + // comments 3 }) `, output: ` @@ -348,22 +349,97 @@ const tests = { a: { a: 1, b: 2, - // comments + // comments 1 c: 3, d: 4, }, - // comments + // comments 2 b: { a: 1, b: 2, }, c: {}, d: {}, + // comments 3 }) `, errors: [ - { message: "Expected style properties to be in ascending order. 'c' should be before 'd'." }, - { message: "Expected class names to be in ascending order. 'c' should be before 'd'." }, + { + message: + "Expected style properties to be in ascending order. 'c' should be before 'd'.", + }, + { + message: + "Expected class names to be in ascending order. 'c' should be before 'd'.", + }, + ], + }, + { + code: ` + const styles = StyleSheet.create({ + a: { + d: 4, + // singleline 1 + // singleline 2 + // singleline 3 + c: 3, + a: 1, + b: 2, + }, + d: {}, + c: {}, + /* + multiline 1 + */ + /* + multiline 2 + */ + /* + multiline 3 + */ + b: { + a: 1, + b: 2, + }, + }) + `, + output: ` + const styles = StyleSheet.create({ + a: { + a: 1, + b: 2, + // singleline 1 + // singleline 2 + // singleline 3 + c: 3, + d: 4, + }, + /* + multiline 1 + */ + /* + multiline 2 + */ + /* + multiline 3 + */ + b: { + a: 1, + b: 2, + }, + c: {}, + d: {}, + }) + `, + errors: [ + { + message: + "Expected style properties to be in ascending order. 'c' should be before 'd'.", + }, + { + message: + "Expected class names to be in ascending order. 'c' should be before 'd'.", + }, ], }, ], From 11ccc85815a8488af8bd6bfee44f1e4a8fcae686 Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Fri, 15 Mar 2019 15:17:39 +0800 Subject: [PATCH 4/5] handle shorthand edge case --- lib/rules/sort-styles.js | 12 +- lib/util/stylesheet.js | 10 ++ tests/lib/rules/sort-styles.js | 237 ++++++++++++++++++++++++++++++++- 3 files changed, 251 insertions(+), 8 deletions(-) diff --git a/lib/rules/sort-styles.js b/lib/rules/sort-styles.js index aa39f44..d6688e3 100644 --- a/lib/rules/sort-styles.js +++ b/lib/rules/sort-styles.js @@ -16,6 +16,7 @@ const { getPropertiesChunks, getStylePropertyIdentifier, isStyleSheetDeclaration, + isEitherShortHand, } = astHelpers; //------------------------------------------------------------------------------ @@ -37,7 +38,9 @@ module.exports = (context) => { const identifierB = getStylePropertyIdentifier(b); let sortOrder = 0; - if (identifierA < identifierB) { + if (isEitherShortHand(identifierA, identifierB)) { + return a.range[0] - b.range[0]; + } else if (identifierA < identifierB) { sortOrder = -1; } else if (identifierA > identifierB) { sortOrder = 1; @@ -91,6 +94,13 @@ module.exports = (context) => { const prevName = getStylePropertyIdentifier(previous); const currentName = getStylePropertyIdentifier(current); + if ( + arrayName === 'style properties' && + isEitherShortHand(prevName, currentName) + ) { + return; + } + if (!isValidOrder(prevName, currentName)) { return report(array, arrayName, node, previous, current); } diff --git a/lib/util/stylesheet.js b/lib/util/stylesheet.js index 051b384..c9b2b14 100644 --- a/lib/util/stylesheet.js +++ b/lib/util/stylesheet.js @@ -477,6 +477,16 @@ const astHelpers = { return [node.object.name, node.property.name].join('.'); } }, + + isEitherShortHand: function (property1, property2) { + const shorthands = ['margin', 'padding', 'border', 'flex']; + if (shorthands.includes(property1)) { + return property2.startsWith(property1); + } else if (shorthands.includes(property2)) { + return property1.startsWith(property2); + } + return false; + }, }; module.exports.astHelpers = astHelpers; diff --git a/tests/lib/rules/sort-styles.js b/tests/lib/rules/sort-styles.js index c2f6af5..157bfa2 100644 --- a/tests/lib/rules/sort-styles.js +++ b/tests/lib/rules/sort-styles.js @@ -142,6 +142,52 @@ const tests = { }) `, }, + { + code: ` + const styles = StyleSheet.create({ + a: { + margin: 1, + marginLeft: 1, + }, + b: { + border: 1, + borderLeft: 1, + }, + c: { + padding: 1, + paddingLeft: 1, + }, + d: { + flex: 1, + flexGrow: 1, + } + }) + `, + options: ['asc'], + }, + { + code: ` + const styles = StyleSheet.create({ + d: { + marginLeft: 1, + margin: 1, + }, + c: { + border: 1, + borderLeft: 1, + }, + b: { + padding: 1, + paddingLeft: 1, + }, + a: { + flex: 1, + flexGrow: 1, + } + }) + `, + options: ['desc'], + }, ], invalid: [ { @@ -165,7 +211,8 @@ const tests = { `, errors: [ { - message: "Expected style properties to be in ascending order. 'x' should be before 'y'.", + message: + "Expected style properties to be in ascending order. 'x' should be before 'y'.", }, ], }, @@ -196,7 +243,8 @@ const tests = { `, errors: [ { - message: "Expected class names to be in ascending order. 'a' should be before 'b'.", + message: + "Expected class names to be in ascending order. 'a' should be before 'b'.", }, ], }, @@ -222,7 +270,8 @@ const tests = { `, errors: [ { - message: "Expected class names to be in ascending order. 'c' should be before 'd'.", + message: + "Expected class names to be in ascending order. 'c' should be before 'd'.", }, ], }, @@ -241,7 +290,8 @@ const tests = { `, errors: [ { - message: "Expected class names to be in ascending order. 'a' should be before 'b'.", + message: + "Expected class names to be in ascending order. 'a' should be before 'b'.", }, ], }, @@ -314,13 +364,16 @@ const tests = { `, errors: [ { - message: "Expected style properties to be in ascending order. 'x' should be before 'y'.", + message: + "Expected style properties to be in ascending order. 'x' should be before 'y'.", }, { - message: "Expected style properties to be in ascending order. 'c' should be before 'd'.", + message: + "Expected style properties to be in ascending order. 'c' should be before 'd'.", }, { - message: "Expected class names to be in ascending order. 'c' should be before 'd'.", + message: + "Expected class names to be in ascending order. 'c' should be before 'd'.", }, ], }, @@ -442,6 +495,176 @@ const tests = { }, ], }, + { + code: ` + const styles = StyleSheet.create({ + a: { + z: 1, + margin: 1, + b: 1, + marginLeft: 1, + a: 1, + }, + b: { + z: 1, + b: 1, + border: 1, + borderLeft: 1, + a: 1, + }, + c: { + z: 1, + padding: 1, + paddingLeft: 1, + b: 1, + a: 1, + }, + d: { + flex: 1, + z: 1, + b: 1, + flexGrow: 1, + a: 1, + } + }) + `, + output: ` + const styles = StyleSheet.create({ + a: { + a: 1, + b: 1, + margin: 1, + marginLeft: 1, + z: 1, + }, + b: { + a: 1, + b: 1, + border: 1, + borderLeft: 1, + z: 1, + }, + c: { + a: 1, + b: 1, + padding: 1, + paddingLeft: 1, + z: 1, + }, + d: { + a: 1, + b: 1, + flex: 1, + flexGrow: 1, + z: 1, + } + }) + `, + options: ['asc'], + errors: [ + { + message: + "Expected style properties to be in ascending order. 'margin' should be before 'z'.", + }, + { + message: + "Expected style properties to be in ascending order. 'b' should be before 'z'.", + }, + { + message: + "Expected style properties to be in ascending order. 'padding' should be before 'z'.", + }, + { + message: + "Expected style properties to be in ascending order. 'b' should be before 'z'.", + }, + ], + }, + { + code: ` + const styles = StyleSheet.create({ + d: { + a: 1, + marginLeft: 1, + b: 1, + margin: 1, + z: 1, + }, + c: { + a: 1, + b: 1, + border: 1, + borderLeft: 1, + z: 1, + }, + b: { + a: 1, + padding: 1, + paddingLeft: 1, + b: 1, + z: 1, + }, + a: { + flex: 1, + a: 1, + b: 1, + flexGrow: 1, + z: 1, + } + }) + `, + output: ` + const styles = StyleSheet.create({ + d: { + z: 1, + marginLeft: 1, + margin: 1, + b: 1, + a: 1, + }, + c: { + z: 1, + border: 1, + borderLeft: 1, + b: 1, + a: 1, + }, + b: { + z: 1, + padding: 1, + paddingLeft: 1, + b: 1, + a: 1, + }, + a: { + z: 1, + flex: 1, + flexGrow: 1, + b: 1, + a: 1, + } + }) + `, + options: ['desc'], + errors: [ + { + message: + "Expected style properties to be in descending order. 'marginLeft' should be before 'a'.", + }, + { + message: + "Expected style properties to be in descending order. 'b' should be before 'a'.", + }, + { + message: + "Expected style properties to be in descending order. 'padding' should be before 'a'.", + }, + { + message: + "Expected style properties to be in descending order. 'b' should be before 'a'.", + }, + ], + }, ], }; From f6986cb484579e47c51e8fe36ad8f2552a507bfd Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Fri, 15 Mar 2019 19:08:43 +0800 Subject: [PATCH 5/5] no autofix if have comments --- lib/rules/sort-styles.js | 25 ++++++------ tests/lib/rules/sort-styles.js | 74 ++-------------------------------- 2 files changed, 15 insertions(+), 84 deletions(-) diff --git a/lib/rules/sort-styles.js b/lib/rules/sort-styles.js index d6688e3..44d8279 100644 --- a/lib/rules/sort-styles.js +++ b/lib/rules/sort-styles.js @@ -49,30 +49,29 @@ module.exports = (context) => { }); } - function getActualRange(node) { - const range = [].concat(node.range); - range[0] = sourceCode - .getCommentsBefore(node) - .reduce((start, comment) => Math.min(start, comment.range[0]), range[0]); - return range; - } - function report(array, type, node, prev, current) { const currentName = getStylePropertyIdentifier(current); const prevName = getStylePropertyIdentifier(prev); + const hasComments = array + .map(prop => sourceCode.getComments(prop)) + .reduce( + (hasComment, comment) => + hasComment || comment.leading.length > 0 || comment.trailing > 0, + false + ); + context.report({ node, message: `Expected ${type} to be in ${order}ending order. '${currentName}' should be before '${prevName}'.`, loc: current.key.loc, - fix(fixer) { + fix: hasComments ? undefined : (fixer) => { const sortedArray = sort(array); return array .map((item, i) => { if (item !== sortedArray[i]) { - const actualRange = getActualRange(sortedArray[i]); - return fixer.replaceTextRange( - getActualRange(item), - sourceCode.text.slice(actualRange[0], actualRange[1]) + return fixer.replaceText( + item, + sourceCode.getText(sortedArray[i]) ); } return null; diff --git a/tests/lib/rules/sort-styles.js b/tests/lib/rules/sort-styles.js index 157bfa2..e687600 100644 --- a/tests/lib/rules/sort-styles.js +++ b/tests/lib/rules/sort-styles.js @@ -398,90 +398,22 @@ const tests = { }) `, output: ` - const styles = StyleSheet.create({ - a: { - a: 1, - b: 2, - // comments 1 - c: 3, - d: 4, - }, - // comments 2 - b: { - a: 1, - b: 2, - }, - c: {}, - d: {}, - // comments 3 - }) - `, - errors: [ - { - message: - "Expected style properties to be in ascending order. 'c' should be before 'd'.", - }, - { - message: - "Expected class names to be in ascending order. 'c' should be before 'd'.", - }, - ], - }, - { - code: ` const styles = StyleSheet.create({ a: { d: 4, - // singleline 1 - // singleline 2 - // singleline 3 + // comments 1 c: 3, a: 1, b: 2, }, d: {}, c: {}, - /* - multiline 1 - */ - /* - multiline 2 - */ - /* - multiline 3 - */ - b: { - a: 1, - b: 2, - }, - }) - `, - output: ` - const styles = StyleSheet.create({ - a: { - a: 1, - b: 2, - // singleline 1 - // singleline 2 - // singleline 3 - c: 3, - d: 4, - }, - /* - multiline 1 - */ - /* - multiline 2 - */ - /* - multiline 3 - */ + // comments 2 b: { a: 1, b: 2, }, - c: {}, - d: {}, + // comments 3 }) `, errors: [