Skip to content
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

Merged

Conversation

barraq
Copy link
Contributor

@barraq barraq commented Dec 29, 2016

Description

plugin_directories property can be used in .scss-lint.yml to load additional linters from a directory. However it does not allow loading custom .scss-lint.yml for such directory.

This PR allows loading a custom .scss-lint.yml from any directory specified in plugin_directories and merge it with your existing configuration. This is pretty handy to allow extending your existing configuration from other configuration coming from other non-gem package, e.g. npm, bower, etc.

What was done

  • Update linter_dir.rb to add loading custom .scss-lint.yml functionality (based on linter_gem)
  • Update the spec accordingly

Note

While scss-linter allows loading .scss-lint.yml file from other gems it sometimes happen that you need to extend your project config from another .scss-lint.yml that is not coming from a gem but from another directory or another non-gem package, like npm, bower, etc.

# .scss-lint.yml
plugin_directories: ['.scss-linters', 'node_modules/custom_package']

Might be related to #516

`plugin_directories` property can be used in `.scss-linter.yml` to
load additional linters from a directory. However it does not allow
loading custom `.scss-linter.yml` for such directory.

This commit allows loading a custom `.scss-linter.yml` from any
directory specified in `plugin_directories` and merge it with
your existing configuration.
@barraq barraq force-pushed the feature/allow-loading-config-file-from-plugin-dir branch from 80f6fff to 787c381 Compare December 29, 2016 17:33
#
# @return [String]
def plugin_config_file
File.join(@dir, Config::FILE_NAME)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To reduce indirection, this line could probably be inlined directly in the plugin_config method (since you don't use it elsewhere).

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 ;)

# Returns the {SCSSLint::Config} for this directory.
#
# This is intended to be merged with the configuration that loaded this
# plugin.
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

@barraq
Copy link
Contributor Author

barraq commented Jan 2, 2017

Hi @trotzig thanks for taking time to review this PR 👍

@trotzig
Copy link
Contributor

trotzig commented Jan 3, 2017

Thanks @barraq! I'm waiting to hear back from a person with more context on the setup. I'll get back soon.

@trotzig trotzig merged commit 3dcb923 into sds:master Jan 5, 2017
@trotzig
Copy link
Contributor

trotzig commented Jan 5, 2017

Thanks for the contribution @barraq! I'm going to include this in a 0.52.0 release which will be published as soon as I have permissions to push to rubygems.org.

@barraq
Copy link
Contributor Author

barraq commented Jan 5, 2017

Awesome :D thanks

@trotzig
Copy link
Contributor

trotzig commented Jan 5, 2017

Okay, it's been released now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants