Skip to content

Commit

Permalink
Merge pull request #6 from a-tokyo/hotfix/disablefix
Browse files Browse the repository at this point in the history
✨ warn about issues and dont fix if disableFix is true
  • Loading branch information
a-tokyo authored Oct 31, 2024
2 parents abca6d9 + 5342e78 commit 4133f5e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
node_modules
.vscode
.DS_Store
12 changes: 8 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const defaultSecondaryOptions = {
ignoreAtRules: ['media'],
/** Base font size - used by autofix to convert px to rem */
fontSize: 16,
/** New: disable auto-fixing */
disableFix: false,
};

/** Regex to match pixels declarations in a string */
Expand Down Expand Up @@ -145,15 +147,17 @@ const pluginHandler =
return;
}

const { disableFix, fontSize } = secondaryOptionObject;

/* check for declarations */
root.walkDecls((declaration) => {
if (_hasForbiddenPX(declaration, secondaryOptionObject)) {
/* handle fixing */
if (context.fix) {
if (context.fix && !disableFix) {
// Apply fixes using PostCSS API
declaration.value = _pxToRem(
declaration.value,
secondaryOptionObject.fontSize,
fontSize,
);

// Return and don't report a problem
Expand All @@ -174,9 +178,9 @@ const pluginHandler =
root.walkAtRules((atRule) => {
if (_hasForbiddenPX(atRule, secondaryOptionObject)) {
/* handle fixing */
if (context.fix) {
if (context.fix && !disableFix) {
// Apply fixes using PostCSS API
atRule.value = _pxToRem(atRule.value, secondaryOptionObject.fontSize);
atRule.value = _pxToRem(atRule.value, fontSize);

// Return and don't report a problem
return;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "stylelint-rem-over-px",
"version": "1.0.1",
"version": "1.0.2",
"description": "A stylelint rule to enforce the usage of rem units over px units.",
"main": "index.js",
"files": [
Expand Down

0 comments on commit 4133f5e

Please sign in to comment.