-
Notifications
You must be signed in to change notification settings - Fork 464
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
Allow loading config file from plugin directory #878
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,11 +6,11 @@ class LinterDir | |
|
||
def initialize(dir) | ||
@dir = dir | ||
@config = SCSSLint::Config.new({}) # Will always be empty | ||
end | ||
|
||
def load | ||
ruby_files.each { |file| require file } | ||
@config = plugin_config | ||
self | ||
end | ||
|
||
|
@@ -19,6 +19,29 @@ def load | |
def ruby_files | ||
Dir.glob(File.expand_path(File.join(@dir, '**', '*.rb'))) | ||
end | ||
|
||
# Returns the {SCSSLint::Config} for this directory. | ||
# | ||
# This is intended to be merged with the configuration that loaded this | ||
# plugin. | ||
# | ||
# @return [SCSSLint::Config] | ||
def plugin_config | ||
file = plugin_config_file | ||
|
||
if File.exist?(file) | ||
Config.load(file, merge_with_default: false) | ||
else | ||
Config.new({}) | ||
end | ||
end | ||
|
||
# Path of the configuration file to attempt to load for this directory. | ||
# | ||
# @return [String] | ||
def plugin_config_file | ||
File.join(@dir, Config::FILE_NAME) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To reduce indirection, this line could probably be inlined directly in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried to keep as close a PluginGem structure (https://github.com/brigade/scss-lint/blob/master/lib/scss_lint/plugins/linter_gem.rb#L44) but yes it can be inlined; unless we want to test it (which we don't). I can remove it ;) |
||
end | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment confuses me a little since we use
merge_with_default: false
below. What is indented to merge, and where does that happen? I don't have a lot of context on how scss-lint configuration works, so excuse me if I'm missing something obvious.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Plugins are loaded in Config.rb (see https://github.com/brigade/scss-lint/blob/master/lib/scss_lint/config.rb#L235 and https://github.com/brigade/scss-lint/blob/master/lib/scss_lint/plugins.rb). Basically each plugin is loaded and brings its own configuration. Then all those configs are merged into one config and eventually (unless specified otherwise in the main .scss-lint.yml or cli option) merge with the default.yml config. Therefore, each plugin should avoid merging its config from default as it is done at the end of the process.
I borrowed the comment from https://github.com/brigade/scss-lint/blob/master/lib/scss_lint/plugins/linter_gem.rb#L25 for consistency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation, that makes sense.