Skip to content
Permalink
Browse files

Fix: revert changes to key-spacing due to regression (#12598)

Revert "Update: Fix uglified object align in key-spacing (fixes #11414) (#12472)"

This reverts commit 6503cb8.
  • Loading branch information
kaicataldo authored and btmills committed Nov 25, 2019
1 parent c644b54 commit dd1e9f4df2103c43509a54b0ad5f9106557997f9
Showing with 2 additions and 449 deletions.
  1. +2 −28 lib/rules/key-spacing.js
  2. +0 −421 tests/lib/rules/key-spacing.js
@@ -42,30 +42,6 @@ function isSingleLine(node) {
return (node.loc.end.line === node.loc.start.line);
}

/**
* Checks whether both nodes are on the same line.
* @param {ASTNode} nodeA AST Node being evaluated.
* @param {ASTNode} nodeB AST Node being evaluated.
* @returns {boolean} True if both nodes are on the same line.
*/
function isOnSameLine(nodeA, nodeB) {
return (nodeA.loc.end.line === nodeB.loc.end.line);
}

/**
* Checks whether the properties of a node on the same line.
* @param {ASTNode} node node
* @returns {boolean} True if the properties of a node are on the same line.
*/
function isPropertiesOnSameLine(node) {
if (node.properties.length <= 1) {
return true;
}
const [firstProperty] = node.properties;

return node.properties.every(property => isOnSameLine(firstProperty, property));
}

/**
* Initializes a single option property from the configuration with defaults for undefined values
* @param {Object} toOptions Object to be initialized
@@ -654,7 +630,7 @@ module.exports = {

return {
ObjectExpression(node) {
if (isSingleLine(node) || isPropertiesOnSameLine(node)) {
if (isSingleLine(node)) {
verifyListSpacing(node.properties.filter(isKeyValueProperty));
} else {
verifyAlignment(node);
@@ -667,9 +643,7 @@ module.exports = {
// Obey beforeColon and afterColon in each property as configured
return {
Property(node) {
const option = (isSingleLine(node.parent) || isPropertiesOnSameLine(node.parent)) ? singleLineOptions : multiLineOptions;

verifySpacing(node, option);
verifySpacing(node, isSingleLine(node.parent) ? singleLineOptions : multiLineOptions);
}
};

0 comments on commit dd1e9f4

Please sign in to comment.
You can’t perform that action at this time.