Stylus Linter
- Issues
- Installation
- Example cli Usage
- CLI
- Non CLI Usage
- As Part of Your Workflow
- Ignore errors
- Rules
- License
Installation
As part of your project
npm i stlint -D
As a cli tool:
npm install stlint -g
Example cli Usage:
npx stlint
Run stlint on cwd
stlint
Run stlint on cwd as global
stlint path/to/filename.styl
Run stlint on a file
stlint path/to/dir --watch
Watch dir, run stlint on file change
stlint --help
Get list of commands
stlint --version
Get version number
stlint --config path/to/config/.configrc
Run stlint with custom config settings
stlint styl/ --watch -c path/to/config/.configrc
Watch dir, use custom config
stlint --command autocomplete --content #e --offset 0 --lineoffset 0
Get autocomplete suggestions for #
string
CLI
-h
or --help
Display list of commands
-w
or --watch
Watch file or directory and run lint on change
-c
or --config
Pass in location of custom config file
-v
or --version
Display current version
-g
or --grep
Only run rules matching this string or regexp
-f
or --fix
Try fix some issues
-i
or --info
Show info about version and config (can be used with --grep for filter rules)
-r
or --reporter
Reporter "raw", "json" or "silent"
All another options from config
Non CLI Usage
const StylusLinter = StylusLinter;;
or check only one file or text
const Linter = Linter;const linter = ...options; // if you want check contentlinter; // if you want check filelinter; // and display errors.linterdisplay;
Config file
Create .stlintrc
file in project root
As Part of Your Workflow
Stlint integrations with IDEs are available.
Ignore errors
sometimes you want to ignore the error for this there are two directives:
@stlint-ignore
- ignores only one line after it@stlint-disable
@stlint-enable
- ignore block (@stlint-enable is optional)
For example, in the following code, some errors will be ignored.
$p = { a: #CCC // @stlint-ignore b: #ccc // need use uppercase notation will be ignored c: 10px}.test margin-top 20px // @stlint-disable padding-top 20px // need use mixin will be ignored color #ccc // need use uppercase notation and use variable will be ignored // @stlint-enable background-color #ddd
Respectively, in order not to display errors of the entire file, it is enough to add an
@stlint-disable
directive to its beginning
// @stlint-disable - all errors below will be ignored$p = { a: #CCC b: #ccc c: 10px}.test margin-top 20px padding-top 20px color #ccc background-color #ddd
Rules
brackets
Check for brackets
Default value
colons
Use/Do not use colons after property
Default value
color
Process all color values. Allow or deny use it not in variable and use uppercase or lowercase statements
For example this code has error - because we use only color in uppercase
.test color #ccc
If allowOnlyInVar
=== true code above also has error - no use color without variable
Fixed code
$color = #CCC.test color $color
Default value
commaInObject
Allow or deny commas in object hash
Default value
depthControl
Control depth spaces or tab
Default value
emptyLines
Check if document has several empty lines
Default value
true
leadingZero
Check for leading 0 on numbers ( 0.5 )
Default value
mixedSpaces
check for mixed spaces and tabs
Default value
prefixVarsWithDollar
Check that $ is used when declaring vars
Default value
quotePref
Check that quote style is consistent with config
Default value
semicolons
Check that selector properties are sorted accordingly
Default value
sortOrder
Rule for checking properties order. Can use alphabetical order or order from grouped array
Default value
useMixinInsteadUnit
Allo or deny some mixin instead of unit statement
Default value
----
Self rules
You can create folder and use it for extra rules
In this folder you can create native JavaScript files
const Rgb = astRGB; { nodesFilter = 'rgb'; // can be one of https://github.com/stylus/stlint/tree/master/src/core/ast /** * Check the AST nodes * @param node */ this { if node instanceof Rgb console; // test111 console; // 112 // this.msg('Test error on test node', node.lineno, node.column, node.line.length); }; /** * Check every line * @param line */ this { if linelineno === 1 // this.msg('Test error on test line', line.lineno, 1, line.line.length); };} moduleexportsTestRule = TestRule;
And you need add this rule in your config