@@ -8,7 +8,6 @@ let helpers;
8
8
let dirname ;
9
9
let stylelint ;
10
10
let assignDeep ;
11
- let presetConfig ;
12
11
13
12
function loadDeps ( ) {
14
13
if ( ! helpers ) {
@@ -23,9 +22,6 @@ function loadDeps() {
23
22
if ( ! assignDeep ) {
24
23
assignDeep = require ( 'assign-deep' ) ;
25
24
}
26
- if ( ! presetConfig ) {
27
- presetConfig = require ( 'stylelint-config-standard' ) ;
28
- }
29
25
}
30
26
31
27
export default {
@@ -44,11 +40,21 @@ export default {
44
40
45
41
this . subscriptions = new CompositeDisposable ( ) ;
46
42
this . subscriptions . add (
47
- atom . config . observe ( 'linter-stylelint.useStandard' , ( value ) => {
48
- this . useStandard = value ;
49
- } ) ,
50
43
atom . config . observe ( 'linter-stylelint.disableWhenNoConfig' , ( value ) => {
51
44
this . disableWhenNoConfig = value ;
45
+ if ( this . useStandard && this . disableWhenNoConfig ) {
46
+ // Disable using the standard if it is desired to stop linting with
47
+ // no configuration
48
+ atom . config . set ( 'linter-stylelint.useStandard' , false ) ;
49
+ }
50
+ } ) ,
51
+ atom . config . observe ( 'linter-stylelint.useStandard' , ( value ) => {
52
+ this . useStandard = value ;
53
+ if ( this . useStandard && this . disableWhenNoConfig ) {
54
+ // Disable disabling linting when there is no configuration as the
55
+ // standard configuration will always be available.
56
+ atom . config . set ( 'linter-stylelint.disableWhenNoConfig' , false ) ;
57
+ }
52
58
} ) ,
53
59
atom . config . observe ( 'linter-stylelint.showIgnored' , ( value ) => {
54
60
this . showIgnored = value ;
@@ -86,7 +92,6 @@ export default {
86
92
loadDeps ( ) ;
87
93
88
94
helpers . startMeasure ( 'linter-stylelint: Lint' ) ;
89
- const scopes = editor . getLastCursor ( ) . getScopeDescriptor ( ) . getScopesArray ( ) ;
90
95
91
96
const filePath = editor . getPath ( ) ;
92
97
const text = editor . getText ( ) ;
@@ -96,55 +101,26 @@ export default {
96
101
return [ ] ;
97
102
}
98
103
99
- // Setup base config if useStandard() is true
100
- const defaultConfig = {
101
- rules : { }
102
- } ;
103
-
104
- // Base the config in the project directory
105
- let [ configBasedir ] = atom . project . relativizePath ( filePath ) ;
106
- if ( configBasedir === null ) {
107
- // Falling back to the file directory if no project is found
108
- configBasedir = dirname ( filePath ) ;
109
- }
110
-
111
- const rules = this . useStandard ? assignDeep ( { } , presetConfig ) : defaultConfig ;
112
-
104
+ const rules = { } ;
113
105
const options = {
114
106
code : text ,
115
107
codeFilename : filePath ,
116
- config : rules ,
117
- configBasedir
108
+ config : { rules }
118
109
} ;
119
110
120
- if ( this . coreIgnored ) {
121
- // When Atom (and thus Linter) is set to allow ignored files, tell
122
- // Stylelint to do the same.
123
- options . disableDefaultIgnores = true ;
124
- }
125
-
111
+ const scopes = editor . getLastCursor ( ) . getScopeDescriptor ( ) . getScopesArray ( ) ;
126
112
if ( scopes . includes ( 'source.css.scss' ) || scopes . includes ( 'source.scss' ) ) {
127
113
options . syntax = 'scss' ;
128
- }
129
- if ( scopes . includes ( 'source.css.less' ) || scopes . includes ( 'source.less' ) ) {
114
+ } else if ( scopes . includes ( 'source.css.less' ) || scopes . includes ( 'source.less' ) ) {
130
115
options . syntax = 'less' ;
131
- }
132
- if ( scopes . includes ( 'source.css.postcss.sugarss' ) ) {
116
+ } else if ( scopes . includes ( 'source.css.postcss.sugarss' ) ) {
133
117
options . syntax = 'sugarss' ;
134
- // `stylelint-config-standard` isn't fully compatible with SugarSS
135
- // See here for details:
136
- // https://github.com/stylelint/stylelint-config-standard#using-the-config-with-sugarss-syntax
137
- options . config . rules [ 'block-closing-brace-empty-line-before' ] = null ;
138
- options . config . rules [ 'block-closing-brace-newline-after' ] = null ;
139
- options . config . rules [ 'block-closing-brace-newline-before' ] = null ;
140
- options . config . rules [ 'block-closing-brace-space-before' ] = null ;
141
- options . config . rules [ 'block-opening-brace-newline-after' ] = null ;
142
- options . config . rules [ 'block-opening-brace-space-after' ] = null ;
143
- options . config . rules [ 'block-opening-brace-space-before' ] = null ;
144
- options . config . rules [ 'declaration-block-semicolon-newline-after' ] = null ;
145
- options . config . rules [ 'declaration-block-semicolon-space-after' ] = null ;
146
- options . config . rules [ 'declaration-block-semicolon-space-before' ] = null ;
147
- options . config . rules [ 'declaration-block-trailing-semicolon' ] = null ;
118
+ }
119
+
120
+ if ( this . coreIgnored ) {
121
+ // When Atom (and thus Linter) is set to allow ignored files, tell
122
+ // Stylelint to do the same.
123
+ options . disableDefaultIgnores = true ;
148
124
}
149
125
150
126
helpers . startMeasure ( 'linter-stylelint: Create Linter' ) ;
@@ -172,13 +148,21 @@ export default {
172
148
helpers . endMeasure ( 'linter-stylelint: Config' ) ;
173
149
174
150
if ( foundConfig ) {
151
+ // We have a configuration from Stylelint
175
152
options . config = assignDeep ( rules , foundConfig . config ) ;
176
153
options . configBasedir = dirname ( foundConfig . filepath ) ;
177
- }
178
-
179
- if ( ! foundConfig && this . disableWhenNoConfig ) {
154
+ } else if ( this . disableWhenNoConfig ) {
155
+ // No configuration, and linting without one is disabled
180
156
helpers . endMeasure ( 'linter-stylelint: Lint' ) ;
181
157
return [ ] ;
158
+ } else if ( this . useStandard ) {
159
+ // No configuration, but using the standard is enabled
160
+ const defaultConfig = helpers . getDefaultConfig ( options . syntax , filePath ) ;
161
+ assignDeep ( rules , defaultConfig . rules ) ;
162
+ if ( defaultConfig . extends ) {
163
+ options . config . extends = defaultConfig . extends ;
164
+ }
165
+ options . configBasedir = defaultConfig . configBasedir ;
182
166
}
183
167
184
168
helpers . startMeasure ( 'linter-stylelint: Check ignored' ) ;
0 commit comments