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

Node.js API should allow fixing a list of files in-place #7684

Closed
jeff-held-aiven opened this issue May 10, 2024 · 3 comments
Closed

Node.js API should allow fixing a list of files in-place #7684

jeff-held-aiven opened this issue May 10, 2024 · 3 comments
Labels
status: needs discussion triage needs further discussion

Comments

@jeff-held-aiven
Copy link

What is the problem you're trying to solve?

I'm trying to use Stylelint's Node.js API to format my SCSS files programmatically. I can see that I can specify the fix option when calling lint, but this seems to be useful only if you pass code to lint (as shown in the docs). What I instead want to do is the following:

import Stylelint from 'stylelint';

await Stylelint.lint({
  files: 'src/**/*.scss',
  fix: true,
});
// Nothing else to be done; all files should be formatted and overwritten with the fixes

What solution would you like to see?

I would like to be able to do what I described, similar to what ESLint allows.

@Mouvedia Mouvedia added the status: needs discussion triage needs further discussion label May 10, 2024
@ybiquitous
Copy link
Member

@jeff-held-aiven The combination of files and fix works now, doesn't it?

@ybiquitous
Copy link
Member

Demo

test.mjs:

import stylelint from 'stylelint';

await stylelint.lint({
	files: ['test.css'],
	config: { rules: { 'hue-degree-notation': 'angle' } },
	fix: true,
});

Run:

$ cat test.css
a {
  color: hsl(198 28% 50%);
}

$ node test.mjs

$ cat test.css
a {
  color: hsl(198deg 28% 50%);
}

$ npx stylelint -v
16.5.0

Diff:

--- a/test.css
+++ b/test.css
@@ -1,3 +1,3 @@
 a {
-  color: hsl(198 28% 50%);
+  color: hsl(198deg 28% 50%);
 }

@jeff-held-aiven
Copy link
Author

Hm, that seems to work now, and I don't know what I was doing wrong. Thanks for the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs discussion triage needs further discussion
Development

No branches or pull requests

3 participants