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.
-
#preferred ⇒ Object
If this config should be preferred over others.
-
#warnings ⇒ Object
readonly
Returns the value of attribute warnings.
Class Method Summary collapse
- .default ⇒ Object
-
.for_file(file_path) ⇒ Object
Loads the configuration for a given file.
- .linter_name(linter) ⇒ Object
-
.load(file, options = {}) ⇒ Object
Loads a configuration from a file, merging it with the default configuration.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #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.
207 208 209 210 211 212 |
# File 'lib/scss_lint/config.rb', line 207 def initialize() @options = @warnings = [] validate_linters end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
11 12 13 |
# File 'lib/scss_lint/config.rb', line 11 def @options end |
#preferred ⇒ Object
If this config should be preferred over others
10 11 12 |
# File 'lib/scss_lint/config.rb', line 10 def preferred @preferred end |
#warnings ⇒ Object (readonly)
Returns the value of attribute warnings.
11 12 13 |
# File 'lib/scss_lint/config.rb', line 11 def warnings @warnings end |
Class Method Details
.default ⇒ Object
14 15 16 |
# File 'lib/scss_lint/config.rb', line 14 def default load(DEFAULT_FILE, merge_with_default: false) end |
.for_file(file_path) ⇒ Object
Loads the configuration for a given file.
31 32 33 34 35 36 37 38 39 |
# File 'lib/scss_lint/config.rb', line 31 def for_file(file_path) directory = File.dirname(File.(file_path)) @dir_to_config ||= {} @dir_to_config[directory] ||= begin config_file = possible_config_files(directory).find(&:file?) Config.load(config_file.to_s) if config_file end end |
.linter_name(linter) ⇒ Object
41 42 43 44 |
# File 'lib/scss_lint/config.rb', line 41 def linter_name(linter) linter = linter.is_a?(Class) ? linter : linter.class linter.name.split('::')[2..-1].join('::') end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
214 215 216 |
# File 'lib/scss_lint/config.rb', line 214 def ==(other) super || @options == other. end |
#disable_all_linters ⇒ Object
237 238 239 240 241 |
# File 'lib/scss_lint/config.rb', line 237 def disable_all_linters @options['linters'].values.each do |linter_config| linter_config['enabled'] = false end end |
#disable_linter(linter) ⇒ Object
233 234 235 |
# File 'lib/scss_lint/config.rb', line 233 def disable_linter(linter) (linter)['enabled'] = false end |
#enable_linter(linter) ⇒ Object
229 230 231 |
# File 'lib/scss_lint/config.rb', line 229 def enable_linter(linter) (linter)['enabled'] = true end |
#enabled_linters ⇒ Object
219 220 221 222 223 |
# File 'lib/scss_lint/config.rb', line 219 def enabled_linters LinterRegistry.extract_linters_from(@options['linters'].keys).select do |linter| (linter)['enabled'] end end |
#exclude_file(file_path) ⇒ Object
263 264 265 266 267 268 |
# File 'lib/scss_lint/config.rb', line 263 def exclude_file(file_path) abs_path = File.(file_path) @options['exclude'] ||= [] @options['exclude'] << abs_path end |
#excluded_file?(file_path) ⇒ Boolean
247 248 249 250 251 252 253 |
# File 'lib/scss_lint/config.rb', line 247 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
255 256 257 258 259 260 261 |
# File 'lib/scss_lint/config.rb', line 255 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
225 226 227 |
# File 'lib/scss_lint/config.rb', line 225 def linter_enabled?(linter) (linter)['enabled'] end |
#linter_options(linter) ⇒ Object
243 244 245 |
# File 'lib/scss_lint/config.rb', line 243 def (linter) @options['linters'][self.class.linter_name(linter)] end |
#scss_files ⇒ Object
Returns Array.
271 272 273 274 275 276 277 |
# File 'lib/scss_lint/config.rb', line 271 def scss_files if path = @options['scss_files'] Dir[path] else [] end end |