Skip to content

Commit

Permalink
Merge pull request #6 from OpenMindedPrettier/selectorsSameLine
Browse files Browse the repository at this point in the history
Implemented selectorsSameLine
  • Loading branch information
azel-s authored Mar 6, 2024
2 parents f45f2be + f834084 commit 2f6d961
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 21 deletions.
12 changes: 6 additions & 6 deletions dist/esm/standalone.mjs

Large diffs are not rendered by default.

16 changes: 12 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30921,10 +30921,10 @@ var require_utils8 = __commonJS2({
const selector = ruleAncestorNode === null || ruleAncestorNode === void 0 ? void 0 : (_ruleAncestorNode$raw = ruleAncestorNode.raws) === null || _ruleAncestorNode$raw === void 0 ? void 0 : _ruleAncestorNode$raw.selector;
return selector && (selector.startsWith(":import") || selector.startsWith(":export"));
}
function insideAtRuleNode(path, atRuleNameOrAtRuleNames) {
function insideAtRuleNode(path, atRuleNameOrAtRuleNames, options = {}) {
const atRuleNames = Array.isArray(atRuleNameOrAtRuleNames) ? atRuleNameOrAtRuleNames : [atRuleNameOrAtRuleNames];
const atRuleAncestorNode = getAncestorNode(path, "css-atrule");
return atRuleAncestorNode && atRuleNames.includes(atRuleAncestorNode.name.toLowerCase());
return atRuleAncestorNode && atRuleNames.includes(atRuleAncestorNode.name.toLowerCase()) || options.selectorsSameLine === true;
}
function insideURLFunctionInImportAtRuleNode(path) {
const node = path.getValue();
Expand Down Expand Up @@ -31626,7 +31626,7 @@ var require_printer_postcss = __commonJS2({
return node.value;
}
case "selector-root": {
return group([insideAtRuleNode(path, "custom-selector") ? [getAncestorNode(path, "css-atrule").customSelector, line] : "", join([",", insideAtRuleNode(path, ["extend", "custom-selector", "nest"]) ? line : hardline], path.map(print, "nodes"))]);
return group([insideAtRuleNode(path, "custom-selector") ? [getAncestorNode(path, "css-atrule").customSelector, line] : "", join([",", insideAtRuleNode(path, ["extend", "custom-selector", "nest"], options) ? line : hardline], path.map(print, "nodes"))]);
}
case "selector-selector": {
return group(indent(path.map(print, "nodes")));
Expand Down Expand Up @@ -32005,8 +32005,16 @@ var require_options3 = __commonJS2({
"src/language-css/options.js"(exports2, module2) {
"use strict";
var commonOptions = require_common_options();
var CATEGORY_CSS = "css";
module2.exports = {
singleQuote: commonOptions.singleQuote
singleQuote: commonOptions.singleQuote,
selectorsSameLine: {
since: "1.0.0",
category: CATEGORY_CSS,
type: "boolean",
default: false,
description: "allow multiple css selectors to be on the same line"
}
};
}
});
Expand Down
12 changes: 6 additions & 6 deletions dist/standalone.js

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions src/language-css/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@

const commonOptions = require("../common/common-options.js");

const CATEGORY_CSS = "css";

// format based on https://github.com/prettier/prettier/blob/main/src/main/core-options.js
module.exports = {
singleQuote: commonOptions.singleQuote,
selectorsSameLine: {
since: "1.0.0",
category: CATEGORY_CSS,
type: "boolean",
default: false,
description: "allow multiple css selectors to be on the same line"
}
};
2 changes: 1 addition & 1 deletion src/language-css/printer-postcss.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ function genericPrint(path, options, print) {
join(
[
",",
insideAtRuleNode(path, ["extend", "custom-selector", "nest"])
insideAtRuleNode(path, ["extend", "custom-selector", "nest"], options)
? line
: hardline,
],
Expand Down
9 changes: 5 additions & 4 deletions src/language-css/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,19 @@ function insideICSSRuleNode(path) {
);
}

function insideAtRuleNode(path, atRuleNameOrAtRuleNames) {
const atRuleNames = Array.isArray(atRuleNameOrAtRuleNames)
function insideAtRuleNode(path, atRuleNameOrAtRuleNames, options = {}) {
const atRuleNames = Array.isArray(atRuleNameOrAtRuleNames)
? atRuleNameOrAtRuleNames
: [atRuleNameOrAtRuleNames];
const atRuleAncestorNode = getAncestorNode(path, "css-atrule");

return (
atRuleAncestorNode &&
atRuleNames.includes(atRuleAncestorNode.name.toLowerCase())
);
atRuleNames.includes(atRuleAncestorNode.name.toLowerCase()))
|| options.selectorsSameLine === true;
}


function insideURLFunctionInImportAtRuleNode(path) {
const node = path.getValue();
const atRuleAncestorNode = getAncestorNode(path, "css-atrule");
Expand Down

0 comments on commit 2f6d961

Please sign in to comment.