Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ warn about issues and dont fix if disableFix is true #6

Merged
merged 2 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading