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

Add support for custom linters #161

Closed
marcogallotta opened this issue May 9, 2014 · 14 comments
Closed

Add support for custom linters #161

marcogallotta opened this issue May 9, 2014 · 14 comments
Milestone

Comments

@marcogallotta
Copy link

Hey there

I am trying to add custom linters. The code we use to add our linters is included below. It was working in scss-lint version 0.12.0, but not on the latest version. We are enabling it by passing the args "-i ", and the linters are in admin/lint/scss_lint_rules/ and follow the same structure as pre-packaged ones. It just never gets loaded into @options.

Any suggestions on how to get this working? We have also tried enabling it through a config file, but that doesn't seem to do anything.

    require 'scss_lint'

    ASANA_LINT_DIR = "admin/lint/scss_lint_rules/"

    SCSSLint::LinterRegistry.class_eval do
      class << self
        def extract_linters_from(linter_names)
          puts "extracting linters"
          Dir["#{ASANA_LINT_DIR}*.rb"].each do |file|
            require file
          end
          linter_names.map do |linter_name|
            begin
              SCSSLint::Linter.const_get(linter_name)
            rescue NameError
              raise SCSSLint::NoSuchLinter.new("Linter #{linter_name} does not exist")
            end
          end
        end
      end
    end

    SCSSLint::CLI.new(ARGV).tap do |cli|
      puts "parsing args"
      cli.parse_arguments
      puts "running"
      cli.run
    end

and - any chance you'd add the functionality to pass custom linters in? I'm sure lots of other groups have custom lint rules that don't make sense to add to this package, but would be of great use to them.

thanks!!

@geniou
Copy link
Contributor

geniou commented May 12, 2014

Since version 0.12.0 there are a lot of changes - hard to say what's the reason. In General I would think it's always better to contribute to the project and introduce new (configurable) linters instead of keeping them private. So you also don't have to take care on every change, that your private code is still running.

What kind of linters to you have?

@marcogallotta
Copy link
Author

Our usage is fairly basic right now, but we plan to expand on it. We in particular have a linter that prevents pointer event attributes being used in CSS. Maybe other people would like that? Or we could turn it into a linter that disallows event types that a user passes in via config?

@geniou
Copy link
Contributor

geniou commented May 13, 2014

Can you give an example, so that I understand what you are trying to achieve?

@rachelannmiller
Copy link

this is the one linter we currently have:

module SCSSLint
  class Linter::NoPointerEvents < Linter
    include LinterRegistry

    def visit_prop(node)
      add_lint(node) if node.name.first.to_s == 'pointer-events'
    end

    def description
      'IE doesnt support pointer-events.'
    end

  end
end

pretty simple, right? 'm not sure anyone else cares about keeping pointer-events out of their scss, but we were thinking it might be nice to let users keep arbitrary attributes of their choice out of their codebase. ie somewhere in the config file for a linter, list disallowed attributes.

but you could also imagine all kinds of custom rules that don't make sense for everyone - like my PM hates orange, and wants to make sure no one adds any orange to the website. I think first hand functionality to add custom linters would be really useful.

@geniou
Copy link
Contributor

geniou commented May 13, 2014

I think it would be a great linter where I can specify a list of properties, that are banned. It would be diabled by default, and can be enabled if needed.

The configuration could look like this:

ForbiddenProperties:
  enabled: true
  properties:
    - pointer-events
    - something-else

@sds what do you think?

@rachelannmiller
Copy link

geniou - I love that.

@sds
Copy link
Owner

sds commented May 14, 2014

@marcogallotta: One of the big milestones that is holding scss-lint back from a 1.0 release is the ability for repositories to define custom linters. Ideally, what I'd like to see in such a feature is the ability for a developer to define their own hierarchy of linters, identical in structure to the https://github.com/causes/scss-lint/tree/master/lib/scss_lint/linter directory but located in the repository under a customizable directory (for example .scss-linters by default).

I don't think this would be too much work to implement, but it requires some changes to the LinterRegistry and Configuration classes to support it.

If you're interested in having this added to scss-lint, we'd be totally open to a pull request.

@sds
Copy link
Owner

sds commented May 14, 2014

@geniou: I'd accept a pull request for a ForbiddenProperty linter, preferring the singular name rather than the plural as that matches our other linter names.

@sds sds changed the title Custom linters Add support for custom linters May 14, 2014
@asottile
Copy link
Contributor

+1 custom repository-specific linters would be useful

@luizotcarvalho
Copy link

+1 I need to test some guidelines I use in my work, for example, we use variables of the colors palette instead of filling with large amount of hexadecimals on the project. Would be great if a could write a custom test for this.

@aeberlin
Copy link

👍

@dnutels
Copy link

dnutels commented Dec 20, 2014

👍

@gunnx
Copy link

gunnx commented Mar 4, 2015

+1 for ForbiddenProperty

@sds
Copy link
Owner

sds commented May 26, 2015

Experimental support for custom linters was implemented in #459. Please check out the master branch to take it for a spin. Feedback would be appreciated!

@sds sds closed this as completed May 26, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants