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

stylelint error #317

Closed
km-tr opened this issue Oct 23, 2017 · 4 comments
Closed

stylelint error #317

km-tr opened this issue Oct 23, 2017 · 4 comments

Comments

@km-tr
Copy link

km-tr commented Oct 23, 2017

If you have version 4.2.3 or higher, you will get an error when running stylelint

Error: You must use a valid syntax option, either: scss, less or sugarss
    at getCode.then.e (/Users/kumagaya/dev/authense/assets/node_modules/stylelint/lib/getPostcssResult.js:71:17)
@sudo-suhas
Copy link
Collaborator

@km-tr This gives very little to go on. Ideally, you should help us reproduce the error so that we can identify the issue. Could you please share your package.json?

@km-tr
Copy link
Author

km-tr commented Oct 23, 2017

I'm sorry. I am investigating it because it does not reproduce in another repository.

@km-tr
Copy link
Author

km-tr commented Oct 23, 2017

@sudo-suhas
Copy link
Collaborator

@km-tr What you are doing is slightly weird. What is happening is that due to the current configuration, stylelint gets passes the -s flag twice:

λ .\node_modules\.bin\stylelint.cmd -s scss "-s" "scss" "--fix" "E:\somewhere\stylelint-lint-staged-error\assets\style\error.scss"
Error: You must use a valid syntax option, either: scss, less or sugarss
    at getCode.then.code (E:\Projects\experiments\stylelint-lint-staged-error\assets\node_modules\stylelint\lib\getPostcssResult.js:71:17)
    at <anonymous>

Please read this section from the readme - https://github.com/okonet/lint-staged#what-commands-are-supported

You can do any of the following to fix the issue:

rm package.json script:

lint-staged resolves binaries installed in your node_modules automatically. There is no need to add a script to package.json for this.

------------------------- assets/lint-staged.config.js -------------------------
index f6ada90..83ad00e 100644
@@ -1,9 +1,7 @@
-const { scripts } = require('./package.json');
-
 module.exports = {
   gitDir: "../",
   verbose: true,
   linters: {
-    "**/assets/**/*.{css,scss}": [`${scripts.stylelint} --fix`, "git add"],
+    "**/assets/**/*.{css,scss}": ['stylelint -s scss --fix', "git add"],
   },
-}
\ No newline at end of file
+}
----------------------------- assets/package.json -----------------------------
index c1bcb37..5234b12 100644
@@ -4,17 +4,12 @@
   "description": "",
   "main": "index.js",
   "scripts": {
-    "test": "lint-staged",
-    "stylelint": "stylelint -s scss"
+    "test": "lint-staged"
   },
   "author": "kmtr <kumagai@bear.tokyo>",
   "license": "MIT",

rename package.json script:

lint-staged also resolves scripts defined in package.json. However, a script name such as stylelint/eslint is probably a bad idea. Moreover, you definitely do not need to embed the script contents again:

------------------------- assets/lint-staged.config.js -------------------------
index f6ada90..cb79b2b 100644
@@ -1,9 +1,7 @@
-const { scripts } = require('./package.json');
-
 module.exports = {
   gitDir: "../",
   verbose: true,
   linters: {
-    "**/assets/**/*.{css,scss}": [`${scripts.stylelint} --fix`, "git add"],
+    "**/assets/**/*.{css,scss}": ['lint:css --fix', "git add"],
   },
-}
\ No newline at end of file
+}

----------------------------- assets/package.json -----------------------------
index c1bcb37..aa0a923 100644
@@ -5,16 +5,12 @@
   "main": "index.js",
   "scripts": {
     "test": "lint-staged",
-    "stylelint": "stylelint -s scss"
+    "lint:css": "stylelint -s scss"
   },
   "author": "kmtr <kumagai@bear.tokyo>",
   "license": "MIT",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants