vinter 0.6.6 → 0.8.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 +24 -0
- data/lib/vinter/lexer.rb +121 -108
- data/lib/vinter/linter.rb +22 -10
- data/lib/vinter/parser.rb +463 -501
- data/lib/vinter.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e9fbaf8c5cf8f88e2454d0402da0eb39ebbd1bfe740c8fcb96edd4252c1d549d
|
|
4
|
+
data.tar.gz: '0699b40b5f811f28b6692c4fbea634255faa6314d6626ad3649948aea4948c02'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 895bd9ac2880f80566a08726a5715e0897afc2524e285b97648ffac58cfda6d89c7fc678238f69bc6e79bb2fefcfefa86e3ee051d3f9f9fa3a0a3ba398076f65
|
|
7
|
+
data.tar.gz: fc22105c7d49b896841a82042db736bb9c2c44006ae309ea4193bbdf29747a8d05b04d8e3563be5c5d139e9cc536c301dd0fbcce37a3842a0b4dcdb8fbcd4efc
|
data/README.md
CHANGED
|
@@ -93,3 +93,27 @@ issues = linter.lint(content)
|
|
|
93
93
|
3. Commit your changes: `git commit -am 'Add some feature'`
|
|
94
94
|
4. Push to the branch: `git push origin my-new-feature`
|
|
95
95
|
5. Submit a pull request
|
|
96
|
+
|
|
97
|
+
## Real-world plugin benchmark
|
|
98
|
+
|
|
99
|
+
See the [plugin benchmark report](reports/plugin-benchmark.md) for source revisions,
|
|
100
|
+
physical LOC, lint time, throughput, and diagnostic counts. To refresh it from
|
|
101
|
+
clean plugin checkouts, run these commands from the Vinter repository.
|
|
102
|
+
|
|
103
|
+
```sh
|
|
104
|
+
git clone --depth 1 https://github.com/monkoose/vim9-stargate /tmp/vim9-stargate
|
|
105
|
+
git clone --depth 1 https://github.com/ShayHill/vim9-limelight /tmp/vim9-limelight
|
|
106
|
+
ruby script/plugin-benchmark.rb /tmp/vim9-stargate /tmp/vim9-limelight > reports/plugin-benchmark.md
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
For later runs, update the checkouts first. Pass additional checkout paths to
|
|
110
|
+
expand coverage. Use the same machine and revisions for speed comparisons.
|
|
111
|
+
|
|
112
|
+
Exclude a plugin revision from the published corpus when Vim rejects a scanned
|
|
113
|
+
file or fails to compile a function in it, including test fixtures. Recheck the
|
|
114
|
+
failure before adding a newer revision. Two revisions excluded using Vim 9.2:
|
|
115
|
+
|
|
116
|
+
- `Bakudankun/qline.vim@e51daab` — compiling the palette code reaches
|
|
117
|
+
`GetLightlinePalette()` and raises E1027 (missing return statement).
|
|
118
|
+
- `ubaldot/vim9-conversion-aid@a2a49e6` — Vim rejects eight scoped variable
|
|
119
|
+
declarations in `test/expected_script.vim` (E1268 and E1069).
|
data/lib/vinter/lexer.rb
CHANGED
|
@@ -582,6 +582,8 @@ module Vinter
|
|
|
582
582
|
encodings: /\b(latin1|iso|koi8|macroman|cp437|cp737|cp775|cp850|cp852|cp855|cp857|cp860|cp861|cp862|cp863|cp865|cp866|cp869|cp874|cp1250|cp1251|cp1253|cp1254|cp1255|cp1256|cp1257|cp1258|cp932|euc\-jp|sjis|cp949|euc\-kr|cp936|euc\-cn|cp950|big5|euc\-tw|utf\-8|ucs\-2|ucs\-21e|utf\-16|utf\-16le|ucs\-4|ucs\-4le|ansi|japan|korea|prc|chinese|taiwan|utf8|unicode|ucs2be|ucs\-2be|ucs\-4be|utf\-32|utf\-32le)\b/,
|
|
583
583
|
#builtin_funcs: /\b(highlight||normal!|normal|filter|match|extend|redraw!|setbufline)\b/,
|
|
584
584
|
type: /\b(number|list|dict|void|string)\b/,
|
|
585
|
+
mode_command: /\b(?:normal|norm)(?:!)?(?!\w).*$/,
|
|
586
|
+
exec_command: /\b(?:execute|exec|exe)\b(?![:(.]).*$/,
|
|
585
587
|
builtin_funcs: /\b(#{Regexp.union(BUILTINS).source})\b/,
|
|
586
588
|
# Identifiers can include # and special characters
|
|
587
589
|
heredoc: /=<</,
|
|
@@ -591,6 +593,7 @@ module Vinter
|
|
|
591
593
|
number: /\b(0[xX][0-9A-Fa-f]+|0[oO][0-7]+|0[bB][01]+|\d+(\.\d+)?([eE][+-]?\d+)?[smh]?)\b/,
|
|
592
594
|
# Handle both single and double quoted strings
|
|
593
595
|
# string: /"(\\"|[^"])*"|'(\\'|[^'])*'/,
|
|
596
|
+
environment_variable: /\$[A-Za-z_][A-Za-z0-9_]*/,
|
|
594
597
|
register_access: /@[a-zA-Z0-9":.%#=*+~_\/\-]/,
|
|
595
598
|
identifier: /\b[a-zA-Z_][a-zA-Z0-9_#]*/,
|
|
596
599
|
# Vim9 comments use #
|
|
@@ -610,10 +613,12 @@ module Vinter
|
|
|
610
613
|
command_separator: /\|/,
|
|
611
614
|
}
|
|
612
615
|
|
|
613
|
-
CONTINUATION_OPERATORS = %w(. .. + - * / = == ==# ==? != > < >= <= && || ? : -> =>)
|
|
616
|
+
CONTINUATION_OPERATORS = %w(. .. + - * / = == ==# ==? != > < >= <= && || ?? ? : -> =>)
|
|
614
617
|
def initialize(input)
|
|
618
|
+
@vim9script = false
|
|
615
619
|
@input = input
|
|
616
620
|
@tokens = []
|
|
621
|
+
@variables = []
|
|
617
622
|
@position = 0
|
|
618
623
|
@line_num = 1
|
|
619
624
|
@column = 1
|
|
@@ -625,7 +630,7 @@ module Vinter
|
|
|
625
630
|
|
|
626
631
|
# Check for contexts where regex is expected
|
|
627
632
|
return true if recent_tokens.any? { |t|
|
|
628
|
-
t
|
|
633
|
+
t[:line] == @line_num && %w[syntax syn].include?(t[:value]) && [:identifier, :keyword].include?(t[:type])
|
|
629
634
|
}
|
|
630
635
|
|
|
631
636
|
return true if recent_tokens.any? { |t|
|
|
@@ -651,6 +656,49 @@ module Vinter
|
|
|
651
656
|
nil # Return nil if no unescaped newline is found
|
|
652
657
|
end
|
|
653
658
|
|
|
659
|
+
# Legacy assignment and option commands accept comments after a complete
|
|
660
|
+
# value. Expression commands such as echo can take adjacent strings.
|
|
661
|
+
def trailing_legacy_comment?
|
|
662
|
+
previous = @tokens.last
|
|
663
|
+
return false unless previous && previous[:line] == @line_num
|
|
664
|
+
return false unless @input[@position - 1].match?(/[ \t]/)
|
|
665
|
+
return true if previous[:type] == :keyword && %w[else endif endfor endwhile endfunction].include?(previous[:value])
|
|
666
|
+
return false unless [:number, :string, :identifier, :type, :paren_close,
|
|
667
|
+
:bracket_close, :brace_close, :option_variable,
|
|
668
|
+
:global_variable, :local_variable, :arg_variable].include?(previous[:type])
|
|
669
|
+
|
|
670
|
+
line_tokens = @tokens.reverse_each.take_while { |token| token[:line] == @line_num }
|
|
671
|
+
%w[let const set setlocal for if elseif while].include?(line_tokens.last[:value])
|
|
672
|
+
end
|
|
673
|
+
|
|
674
|
+
def tokenize_syntax_arguments
|
|
675
|
+
loop do
|
|
676
|
+
rest = @input[@position..]
|
|
677
|
+
if (continuation = rest.match(/\A[ \t]*\r?\n([ \t]*)\\/))
|
|
678
|
+
@position += continuation.end(0)
|
|
679
|
+
@line_num += 1
|
|
680
|
+
@column = continuation[1].length + 2
|
|
681
|
+
@tokens << { type: :line_continuation, value: "\\", line: @line_num, column: @column - 1 }
|
|
682
|
+
next
|
|
683
|
+
end
|
|
684
|
+
break if rest.empty? || rest.start_with?("\r", "\n", '|')
|
|
685
|
+
|
|
686
|
+
if (space = rest.match(/\A[ \t]+/))
|
|
687
|
+
@position += space.end(0)
|
|
688
|
+
@column += space.end(0)
|
|
689
|
+
next
|
|
690
|
+
end
|
|
691
|
+
|
|
692
|
+
# Match a delimited pattern, including region start=/.../ arguments.
|
|
693
|
+
pattern = rest.match(/\A(?:(?:start|end|skip)=)?([^\w\s\\|])(?:\\[^\r\n]|(?!\1)[^\r\n])*?\1/)
|
|
694
|
+
word = pattern ? pattern[0] : rest[/\A(?:\\[^\r\n]|[^\s|])+/]
|
|
695
|
+
break unless word
|
|
696
|
+
@tokens << { type: pattern ? :regex : :identifier, value: word, line: @line_num, column: @column }
|
|
697
|
+
@position += word.length
|
|
698
|
+
@column += word.length
|
|
699
|
+
end
|
|
700
|
+
end
|
|
701
|
+
|
|
654
702
|
def tokenize
|
|
655
703
|
until @position >= @input.length
|
|
656
704
|
chunk = @input[@position..-1]
|
|
@@ -667,23 +715,48 @@ module Vinter
|
|
|
667
715
|
line_start = temp_pos < 0 || @input[temp_pos] == "\n"
|
|
668
716
|
end
|
|
669
717
|
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
718
|
+
if !@vim9script && chunk.start_with?('"') && (line_start || trailing_legacy_comment?)
|
|
719
|
+
comment = chunk[/[^\n]*/]
|
|
720
|
+
@tokens << { type: :comment, value: comment, line: @line_num, column: @column }
|
|
721
|
+
@position += comment.length
|
|
722
|
+
@column += comment.length
|
|
723
|
+
next
|
|
724
|
+
end
|
|
725
|
+
|
|
726
|
+
# Patterns in syntax definitions use Ex quoting and can contain
|
|
727
|
+
# characters that would start comments or strings in Vimscript.
|
|
728
|
+
if (line_start || @tokens.last&.dig(:value) == '|') &&
|
|
729
|
+
(header = chunk.match(/\A(syn(?:tax)?)[ \t]+(match|region|keyword|cluster)\b[ \t]+(\w+)/))
|
|
730
|
+
command, subcommand, group = header.captures
|
|
731
|
+
@tokens << { type: :keyword, value: command == 'syn' ? 'syntax' : command, line: @line_num, column: @column }
|
|
732
|
+
@tokens << { type: :identifier, value: subcommand, line: @line_num, column: @column + header.begin(2) }
|
|
733
|
+
@tokens << { type: :identifier, value: group, line: @line_num, column: @column + header.begin(3) }
|
|
734
|
+
@position += header.end(0)
|
|
735
|
+
@column += header.end(0)
|
|
736
|
+
tokenize_syntax_arguments
|
|
737
|
+
next
|
|
738
|
+
end
|
|
675
739
|
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
740
|
+
# Ex range commands have their own quoting (including marks such as
|
|
741
|
+
# '[ and search addresses). Keep the address out of expression lexing.
|
|
742
|
+
if line_start && (ex = chunk.match(/\A:(?:(?:[0-9$'])[^|\r\n]*?[ \t]+(?:substitute|sort)\b|substitute\b)(?:\\[^\r\n]|[^|\r\n])*/))
|
|
743
|
+
@tokens << { type: :ex_command_line, value: ex[0], line: @line_num, column: @column }
|
|
744
|
+
@position += ex[0].length
|
|
745
|
+
@column += ex[0].length
|
|
746
|
+
next
|
|
747
|
+
end
|
|
682
748
|
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
749
|
+
# Terminal mappings contain literal key sequences and Ex command text.
|
|
750
|
+
# Tokenizing their RHS as Vim expressions changes its meaning.
|
|
751
|
+
if (line_start || @tokens.last&.dig(:value) == '|') &&
|
|
752
|
+
(mapping = chunk.match(/\A(tnoremap|tmap)(?=[ \t]|\r?$)((?:\\[^\r\n]|\x16[^\r\n]|[^|\r\n])*)/))
|
|
753
|
+
command, arguments = mapping.captures
|
|
754
|
+
@tokens << { type: :terminal_mapping, value: command, arguments: arguments,
|
|
755
|
+
line: @line_num, column: @column }
|
|
756
|
+
@position += mapping[0].length
|
|
757
|
+
@column += mapping[0].length
|
|
758
|
+
next
|
|
759
|
+
end
|
|
687
760
|
|
|
688
761
|
# --- Interpolated String Handling ---
|
|
689
762
|
if chunk.start_with?("$'")
|
|
@@ -774,12 +847,15 @@ module Vinter
|
|
|
774
847
|
# Keep going until we find an unescaped closing quote
|
|
775
848
|
while i < chunk.length
|
|
776
849
|
char = chunk[i]
|
|
777
|
-
next_char = chunk[i + 1]
|
|
850
|
+
next_char = chunk[i + 1]
|
|
778
851
|
|
|
779
852
|
string_value += char
|
|
780
853
|
|
|
781
|
-
if
|
|
782
|
-
|
|
854
|
+
if quote == '"' && char == "\\" && next_char
|
|
855
|
+
string_value += next_char
|
|
856
|
+
i += 1
|
|
857
|
+
elsif quote == "'" && char == quote && next_char == quote
|
|
858
|
+
# A doubled single quote represents a literal apostrophe.
|
|
783
859
|
string_value += next_char
|
|
784
860
|
i += 1
|
|
785
861
|
elsif char == quote
|
|
@@ -806,8 +882,8 @@ module Vinter
|
|
|
806
882
|
end
|
|
807
883
|
|
|
808
884
|
# Add special handling for command options in the tokenize method
|
|
809
|
-
if chunk.start_with?('<q-args>', '<f-args>', '<args>')
|
|
810
|
-
arg_token = chunk.match(/\A(<q-args>|<f-args>|<args>)/)[0]
|
|
885
|
+
if chunk.start_with?('<q-args>', '<f-args>', '<args>', '<q-mods>')
|
|
886
|
+
arg_token = chunk.match(/\A(<q-args>|<f-args>|<args>|<q-mods>)/)[0]
|
|
811
887
|
@tokens << {
|
|
812
888
|
type: :command_arg_placeholder,
|
|
813
889
|
value: arg_token,
|
|
@@ -847,19 +923,6 @@ module Vinter
|
|
|
847
923
|
next
|
|
848
924
|
end
|
|
849
925
|
|
|
850
|
-
# Check for keywords first, before other token types
|
|
851
|
-
if match = chunk.match(/\A\b(if|else|elseif|endif|while|endwhile|for|endfor|def|enddef|function|endfunction|endfunc|return|const|var|final|import|export|class|extends|static|enum|vim9script|abort|autocmd|echoerr|echohl|echomsg|let|unlet|var|setlocal|syntax|highlight|sleep|source)\b/)
|
|
852
|
-
@tokens << {
|
|
853
|
-
type: :keyword,
|
|
854
|
-
value: match[0],
|
|
855
|
-
line: @line_num,
|
|
856
|
-
column: @column
|
|
857
|
-
}
|
|
858
|
-
@column += match[0].length
|
|
859
|
-
@position += match[0].length
|
|
860
|
-
next
|
|
861
|
-
end
|
|
862
|
-
|
|
863
926
|
# Handle Vim scoped option variables with &l: or &g: prefix
|
|
864
927
|
if match = chunk.match(/\A&[lg]:[a-zA-Z_][a-zA-Z0-9_]*/)
|
|
865
928
|
@tokens << {
|
|
@@ -992,7 +1055,8 @@ module Vinter
|
|
|
992
1055
|
end
|
|
993
1056
|
|
|
994
1057
|
# Add support for standalone namespace prefixes (like g:)
|
|
995
|
-
if match = chunk.match(/\A([gbwt]):/)
|
|
1058
|
+
if (match = chunk.match(/\A([gbwt]):/)) &&
|
|
1059
|
+
!(@tokens.last&.dig(:line) == @line_num && %w[var const final].include?(@tokens.last[:value]))
|
|
996
1060
|
@tokens << {
|
|
997
1061
|
type: :namespace_prefix,
|
|
998
1062
|
value: match[0],
|
|
@@ -1006,6 +1070,9 @@ module Vinter
|
|
|
1006
1070
|
|
|
1007
1071
|
# Handle compound assignment operators
|
|
1008
1072
|
if match = chunk.match(/\A(\+=|-=|\*=|\/=|\.\.=|\.=)/)
|
|
1073
|
+
if @tokens.last[:type] == :keyword && @variables.include?(@tokens.last[:value])
|
|
1074
|
+
@tokens.last[:type] = :identifier
|
|
1075
|
+
end
|
|
1009
1076
|
@tokens << {
|
|
1010
1077
|
type: :compound_operator,
|
|
1011
1078
|
value: match[0],
|
|
@@ -1031,7 +1098,7 @@ module Vinter
|
|
|
1031
1098
|
end
|
|
1032
1099
|
|
|
1033
1100
|
# Handle multi-character operators explicitly
|
|
1034
|
-
if match = chunk.match(/\A(
|
|
1101
|
+
if match = chunk.match(/\A(=~#|=~\?|=~|!~#|!~\?|!~|==#|==\?|==|!=#|!=\?|!=|=>\?|=>|>=#|>=\?|>=|<=#|<=\?|<=|[<>][#?]|->#|->\?|->|\.\.|\|\||&&|\?\?)/)
|
|
1035
1102
|
@tokens << {
|
|
1036
1103
|
type: :operator,
|
|
1037
1104
|
value: match[0],
|
|
@@ -1045,31 +1112,9 @@ module Vinter
|
|
|
1045
1112
|
|
|
1046
1113
|
# Handle regex patterns /pattern/ - only in specific contexts
|
|
1047
1114
|
if chunk.start_with?('/') && should_parse_as_regex
|
|
1048
|
-
|
|
1049
|
-
regex_value =
|
|
1050
|
-
|
|
1051
|
-
# Keep going until we find the closing slash
|
|
1052
|
-
while i < chunk.length
|
|
1053
|
-
char = chunk[i]
|
|
1054
|
-
regex_value += char
|
|
1055
|
-
|
|
1056
|
-
if char == '/' && (i == 1 || chunk[i-1] != '\\')
|
|
1057
|
-
# Found closing slash
|
|
1058
|
-
i += 1
|
|
1059
|
-
break
|
|
1060
|
-
end
|
|
1061
|
-
|
|
1062
|
-
i += 1
|
|
1063
|
-
end
|
|
1064
|
-
|
|
1065
|
-
# Add the regex token if we found a closing slash
|
|
1066
|
-
if regex_value.end_with?('/')
|
|
1067
|
-
@tokens << {
|
|
1068
|
-
type: :regex,
|
|
1069
|
-
value: regex_value,
|
|
1070
|
-
line: @line_num,
|
|
1071
|
-
column: @column
|
|
1072
|
-
}
|
|
1115
|
+
# A slash escaped by an odd number of backslashes is pattern text.
|
|
1116
|
+
if (regex_value = chunk[/\A\/(?:\\[^\r\n]|[^\\\/\r\n])*\//])
|
|
1117
|
+
@tokens << { type: :regex, value: regex_value, line: @line_num, column: @column }
|
|
1073
1118
|
@column += regex_value.length
|
|
1074
1119
|
@position += regex_value.length
|
|
1075
1120
|
next
|
|
@@ -1136,55 +1181,12 @@ module Vinter
|
|
|
1136
1181
|
next
|
|
1137
1182
|
end
|
|
1138
1183
|
|
|
1139
|
-
# Handle backslash for line continuation
|
|
1140
|
-
if chunk.start_with?('\\')
|
|
1141
|
-
@tokens << {
|
|
1142
|
-
type: :line_continuation,
|
|
1143
|
-
value: '\\',
|
|
1144
|
-
line: @line_num,
|
|
1145
|
-
column: @column
|
|
1146
|
-
}
|
|
1147
|
-
@column += 1
|
|
1148
|
-
@position += 1
|
|
1149
|
-
|
|
1150
|
-
# If followed by a newline, advance to the next line
|
|
1151
|
-
if @position < @input.length && @input[@position] == "\n"
|
|
1152
|
-
@line_num += 1
|
|
1153
|
-
@column = 1
|
|
1154
|
-
@position += 1
|
|
1155
|
-
end
|
|
1156
|
-
|
|
1157
|
-
# Skip whitespace after the continuation
|
|
1158
|
-
while @position < @input.length && @input[@position] =~ /\s/
|
|
1159
|
-
if @input[@position] == "\n"
|
|
1160
|
-
@line_num += 1
|
|
1161
|
-
@column = 1
|
|
1162
|
-
else
|
|
1163
|
-
@column += 1
|
|
1164
|
-
end
|
|
1165
|
-
@position += 1
|
|
1166
|
-
end
|
|
1167
|
-
|
|
1168
|
-
next
|
|
1169
|
-
end
|
|
1170
|
-
|
|
1171
|
-
# Check for special case where 'function' is followed by '('
|
|
1172
|
-
# which likely means it's used as a built-in function
|
|
1173
|
-
if chunk =~ /\Afunction\s*\(/
|
|
1174
|
-
@tokens << {
|
|
1175
|
-
type: :identifier, # Treat as identifier, not keyword
|
|
1176
|
-
value: 'function',
|
|
1177
|
-
line: @line_num,
|
|
1178
|
-
column: @column
|
|
1179
|
-
}
|
|
1180
|
-
@column += 'function'.length
|
|
1181
|
-
@position += 'function'.length
|
|
1182
|
-
next
|
|
1183
|
-
end
|
|
1184
|
-
|
|
1185
1184
|
match_found = false
|
|
1186
1185
|
|
|
1187
1186
|
TOKEN_TYPES.each do |type, pattern|
|
|
1187
|
+
# echohl takes a highlight group name, including Normal.
|
|
1188
|
+
next if type == :mode_command && @tokens.last&.values_at(:value, :line) == ['echohl', @line_num]
|
|
1189
|
+
|
|
1188
1190
|
if match = chunk.match(/\A(#{pattern})/)
|
|
1189
1191
|
value = match[0]
|
|
1190
1192
|
token = {
|
|
@@ -1193,6 +1195,17 @@ module Vinter
|
|
|
1193
1195
|
line: @line_num,
|
|
1194
1196
|
column: @column
|
|
1195
1197
|
}
|
|
1198
|
+
|
|
1199
|
+
# handling variable names that are also keywords
|
|
1200
|
+
if @tokens.last && @tokens.last[:type] == :keyword && %w[var const final].include?(@tokens.last[:value]) && [:identifier, :keyword, :type].include?(type)
|
|
1201
|
+
@variables << value
|
|
1202
|
+
token[:type] = :identifier
|
|
1203
|
+
end
|
|
1204
|
+
|
|
1205
|
+
#if type != :whitespace
|
|
1206
|
+
#@tokens << token
|
|
1207
|
+
#end
|
|
1208
|
+
@vim9script = true if line_start && token[:type] == :keyword && value == 'vim9script'
|
|
1196
1209
|
@tokens << token unless type == :whitespace
|
|
1197
1210
|
|
|
1198
1211
|
# Update position
|
data/lib/vinter/linter.rb
CHANGED
|
@@ -24,29 +24,26 @@ module Vinter
|
|
|
24
24
|
end
|
|
25
25
|
end)
|
|
26
26
|
|
|
27
|
-
# Rule:
|
|
28
|
-
register_rule(Rule.new("
|
|
27
|
+
# Rule: Variables should have type annotations
|
|
28
|
+
register_rule(Rule.new("missing-type-annotation", "Variable declaration is missing type annotation") do |ast|
|
|
29
29
|
issues = []
|
|
30
30
|
|
|
31
31
|
traverse_ast(ast) do |node|
|
|
32
|
-
if node[:type] == :
|
|
33
|
-
issues << { message: "
|
|
32
|
+
if node[:type] == :variable_declaration && node[:var_type_annotation].nil? && node[:var_type] != 'const'
|
|
33
|
+
issues << { message: "Variable #{node[:name]} should have a type annotation", line: node[:line] || 0, column: node[:column] || 0 }
|
|
34
34
|
end
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
issues
|
|
38
38
|
end)
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
register_rule(Rule.new("missing-type-annotation", "Variable declaration is missing type annotation") do |ast|
|
|
40
|
+
register_rule(Rule.new("prefer-def-over-function", "Prefer def to legacy function declarations") do |ast|
|
|
42
41
|
issues = []
|
|
43
|
-
|
|
44
42
|
traverse_ast(ast) do |node|
|
|
45
|
-
if node[:type] == :
|
|
46
|
-
issues << { message: "
|
|
43
|
+
if node[:type] == :legacy_function
|
|
44
|
+
issues << { message: "Use def for #{node[:name]}", line: node[:line], column: node[:column] }
|
|
47
45
|
end
|
|
48
46
|
end
|
|
49
|
-
|
|
50
47
|
issues
|
|
51
48
|
end)
|
|
52
49
|
|
|
@@ -79,6 +76,21 @@ module Vinter
|
|
|
79
76
|
|
|
80
77
|
issues
|
|
81
78
|
end)
|
|
79
|
+
|
|
80
|
+
# Rule: should use the full name of commands that have abbreviations
|
|
81
|
+
register_rule(Rule.new("use-full-name", "Dont use partial names for commands") do |ast|
|
|
82
|
+
issues = []
|
|
83
|
+
|
|
84
|
+
traverse_ast(ast) do |node|
|
|
85
|
+
if node[:type] == :exec_command
|
|
86
|
+
unless node[:value].start_with?("execute")
|
|
87
|
+
issues << { message: "Use of execute command should use the full name", line: node[:line] }
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
issues
|
|
93
|
+
end)
|
|
82
94
|
end
|
|
83
95
|
|
|
84
96
|
def traverse_ast(node, &block)
|