vinter 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +13 -9
- data/bin/vinter +0 -0
- data/lib/vinter/ast_printer.rb +14 -0
- data/lib/vinter/cli.rb +49 -21
- data/lib/vinter/lexer.rb +402 -20
- data/lib/vinter/linter.rb +28 -3
- data/lib/vinter/parser.rb +2809 -724
- data/lib/vinter.rb +2 -1
- metadata +4 -3
data/lib/vinter/linter.rb
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
+
require "yaml"
|
|
2
|
+
|
|
1
3
|
module Vinter
|
|
2
4
|
class Linter
|
|
3
|
-
def initialize
|
|
5
|
+
def initialize(config_path: nil)
|
|
4
6
|
@rules = []
|
|
7
|
+
@ignored_rules = []
|
|
8
|
+
@config_path = config_path || find_config_path
|
|
9
|
+
load_config
|
|
5
10
|
register_default_rules
|
|
6
11
|
end
|
|
7
12
|
|
|
@@ -94,7 +99,7 @@ module Vinter
|
|
|
94
99
|
lexer = Lexer.new(content)
|
|
95
100
|
tokens = lexer.tokenize
|
|
96
101
|
|
|
97
|
-
parser = Parser.new(tokens)
|
|
102
|
+
parser = Parser.new(tokens, content)
|
|
98
103
|
result = parser.parse
|
|
99
104
|
|
|
100
105
|
issues = []
|
|
@@ -121,8 +126,9 @@ module Vinter
|
|
|
121
126
|
}
|
|
122
127
|
end
|
|
123
128
|
|
|
124
|
-
# Apply rules
|
|
129
|
+
# Apply rules, ignoring those specified in config
|
|
125
130
|
@rules.each do |rule|
|
|
131
|
+
next if @ignored_rules.include?(rule.id)
|
|
126
132
|
rule_issues = rule.apply(result[:ast])
|
|
127
133
|
issues.concat(rule_issues.map { |i| {
|
|
128
134
|
type: :rule,
|
|
@@ -135,6 +141,25 @@ module Vinter
|
|
|
135
141
|
|
|
136
142
|
issues
|
|
137
143
|
end
|
|
144
|
+
|
|
145
|
+
private
|
|
146
|
+
|
|
147
|
+
def find_config_path
|
|
148
|
+
# check for project level config
|
|
149
|
+
project_config = Dir.glob(".vinter{.yaml,.yml,}").first
|
|
150
|
+
project_config if project_config
|
|
151
|
+
|
|
152
|
+
# check for user-level config
|
|
153
|
+
user_config = File.expand_path("~/.vinter")
|
|
154
|
+
user_config if File.exist?(user_config)
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
def load_config
|
|
158
|
+
return unless @config_path && File.exist?(@config_path)
|
|
159
|
+
|
|
160
|
+
config = YAML.load_file(@config_path)
|
|
161
|
+
@ignored_rules = config["ignore_rules"] || []
|
|
162
|
+
end
|
|
138
163
|
end
|
|
139
164
|
|
|
140
165
|
class Rule
|