Class: SCSSLint::Config
- Inherits:
-
Object
- Object
- SCSSLint::Config
- Defined in:
- lib/scss_lint/config.rb
Overview
Loads and manages application configuration.
Constant Summary collapse
- FILE_NAME =
'.scss-lint.yml'
- DEFAULT_FILE =
File.join(SCSS_LINT_HOME, 'config', 'default.yml')
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#warnings ⇒ Object
readonly
Returns the value of attribute warnings.
Class Method Summary collapse
- .default ⇒ Object
- .linter_name(linter) ⇒ Object
-
.load(file, options = {}) ⇒ Object
Loads a configuration from a file, merging it with the default configuration.
Instance Method Summary collapse
- #disable_all_linters ⇒ Object
- #disable_linter(linter) ⇒ Object
- #enable_linter(linter) ⇒ Object
- #enabled_linters ⇒ Object
- #exclude_file(file_path) ⇒ Object
- #excluded_file?(file_path) ⇒ Boolean
- #excluded_file_for_linter?(file_path, linter) ⇒ Boolean
-
#initialize(options) ⇒ Config
constructor
A new instance of Config.
- #linter_enabled?(linter) ⇒ Boolean
- #linter_options(linter) ⇒ Object
-
#scss_files ⇒ Object
Array.
Constructor Details
#initialize(options) ⇒ Config
Returns a new instance of Config.
168 169 170 171 172 173 |
# File 'lib/scss_lint/config.rb', line 168 def initialize() @options = @warnings = [] validate_linters end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
9 10 11 |
# File 'lib/scss_lint/config.rb', line 9 def @options end |
#warnings ⇒ Object (readonly)
Returns the value of attribute warnings.
9 10 11 |
# File 'lib/scss_lint/config.rb', line 9 def warnings @warnings end |
Class Method Details
.default ⇒ Object
12 13 14 |
# File 'lib/scss_lint/config.rb', line 12 def default load(DEFAULT_FILE, merge_with_default: false) end |
.linter_name(linter) ⇒ Object
28 29 30 31 |
# File 'lib/scss_lint/config.rb', line 28 def linter_name(linter) linter = linter.is_a?(Class) ? linter : linter.class linter.name.split('::')[2..-1].join('::') end |
Instance Method Details
#disable_all_linters ⇒ Object
193 194 195 196 197 |
# File 'lib/scss_lint/config.rb', line 193 def disable_all_linters @options['linters'].values.each do |linter_config| linter_config['enabled'] = false end end |
#disable_linter(linter) ⇒ Object
189 190 191 |
# File 'lib/scss_lint/config.rb', line 189 def disable_linter(linter) (linter)['enabled'] = false end |
#enable_linter(linter) ⇒ Object
185 186 187 |
# File 'lib/scss_lint/config.rb', line 185 def enable_linter(linter) (linter)['enabled'] = true end |
#enabled_linters ⇒ Object
175 176 177 178 179 |
# File 'lib/scss_lint/config.rb', line 175 def enabled_linters LinterRegistry.extract_linters_from(@options['linters'].keys).select do |linter| (linter)['enabled'] end end |
#exclude_file(file_path) ⇒ Object
219 220 221 222 223 224 |
# File 'lib/scss_lint/config.rb', line 219 def exclude_file(file_path) abs_path = File.(file_path) @options['exclude'] ||= [] @options['exclude'] << abs_path end |
#excluded_file?(file_path) ⇒ Boolean
203 204 205 206 207 208 209 |
# File 'lib/scss_lint/config.rb', line 203 def excluded_file?(file_path) abs_path = File.(file_path) @options.fetch('exclude', []).any? do |exclusion_glob| File.fnmatch(exclusion_glob, abs_path) end end |
#excluded_file_for_linter?(file_path, linter) ⇒ Boolean
211 212 213 214 215 216 217 |
# File 'lib/scss_lint/config.rb', line 211 def excluded_file_for_linter?(file_path, linter) abs_path = File.(file_path) (linter).fetch('exclude', []).any? do |exclusion_glob| File.fnmatch(exclusion_glob, abs_path) end end |
#linter_enabled?(linter) ⇒ Boolean
181 182 183 |
# File 'lib/scss_lint/config.rb', line 181 def linter_enabled?(linter) (linter)['enabled'] end |
#linter_options(linter) ⇒ Object
199 200 201 |
# File 'lib/scss_lint/config.rb', line 199 def (linter) @options['linters'][self.class.linter_name(linter)] end |
#scss_files ⇒ Object
Returns Array.
227 228 229 230 231 232 233 |
# File 'lib/scss_lint/config.rb', line 227 def scss_files if path = @options['scss_files'] Dir[path] else [] end end |