vinter 0.6.6 → 0.7.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 740cef73c6591002936e85126c021b44d024a11a85423c9dcdf397e3804b1ee4
4
- data.tar.gz: 6bb11262f08e075c8c8a61f3ed868ec90a0a415964b55faea11cdfbfa9bde588
3
+ metadata.gz: e35b8436cd29035d2d4f78482e343da5cbb88f3972dc47487abdf47b28f4f5ee
4
+ data.tar.gz: e6ce76acaf998dc56ea09712c90dea53f348445179dd435f9186c98ab8a3f4f7
5
5
  SHA512:
6
- metadata.gz: 2117bcd01a302140e14a50fd14880d3b3df350faaf9b549fc3c0126320ff8c0fb5758d8d71980ce5f5b9f0de87ab1de93e976b918ab02c8ff044b16f2ebce690
7
- data.tar.gz: c2a28d804dde0a2be5e0b96f49fe40b827ae17f4fc1fa544a7e7ca50ebf3fa92233d4ffd9543aecb4ff1dd264809c230a3fdf93717dd91c72ef08a26d60ee521
6
+ metadata.gz: 01061b7d58353485bc083c77ca992dc14e8c0395d499d4f9aa704f7efb15fd71c2061464248283b46cda8533a68aca3c8a1d7cf091b029de02a673b86aa7d134
7
+ data.tar.gz: e2862a606a016a4ea64a1cd38956dacd816c4e96520ffab058529774106e4484e8905cb72350a83bf1f1870bc8a9d56f54f62899ce9be0167dc22b609b9bb410
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).*$/,
585
587
  builtin_funcs: /\b(#{Regexp.union(BUILTINS).source})\b/,
586
588
  # Identifiers can include # and special characters
587
589
  heredoc: /=<</,
@@ -614,6 +616,7 @@ module Vinter
614
616
  def initialize(input)
615
617
  @input = input
616
618
  @tokens = []
619
+ @variables = []
617
620
  @position = 0
618
621
  @line_num = 1
619
622
  @column = 1
@@ -847,19 +850,6 @@ module Vinter
847
850
  next
848
851
  end
849
852
 
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
853
  # Handle Vim scoped option variables with &l: or &g: prefix
864
854
  if match = chunk.match(/\A&[lg]:[a-zA-Z_][a-zA-Z0-9_]*/)
865
855
  @tokens << {
@@ -1006,6 +996,9 @@ module Vinter
1006
996
 
1007
997
  # Handle compound assignment operators
1008
998
  if match = chunk.match(/\A(\+=|-=|\*=|\/=|\.\.=|\.=)/)
999
+ if @tokens.last[:type] == :keyword && @variables.include?(@tokens.last[:value])
1000
+ @tokens.last[:type] = :identifier
1001
+ end
1009
1002
  @tokens << {
1010
1003
  type: :compound_operator,
1011
1004
  value: match[0],
@@ -1136,52 +1129,6 @@ module Vinter
1136
1129
  next
1137
1130
  end
1138
1131
 
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
1132
  match_found = false
1186
1133
 
1187
1134
  TOKEN_TYPES.each do |type, pattern|
@@ -1193,6 +1140,16 @@ module Vinter
1193
1140
  line: @line_num,
1194
1141
  column: @column
1195
1142
  }
1143
+
1144
+ # handling variable names that are also keywords
1145
+ if !@tokens.empty? && @tokens.last[:value] == 'var'
1146
+ @variables << value
1147
+ token[:type] = :identifier
1148
+ end
1149
+
1150
+ #if type != :whitespace
1151
+ #@tokens << token
1152
+ #end
1196
1153
  @tokens << token unless type == :whitespace
1197
1154
 
1198
1155
  # Update position
data/lib/vinter/linter.rb CHANGED
@@ -24,19 +24,6 @@ module Vinter
24
24
  end
25
25
  end)
26
26
 
27
- # Rule: Prefer def over function in Vim9 script
28
- register_rule(Rule.new("prefer-def-over-function", "Use def instead of function in Vim9 script") do |ast|
29
- issues = []
30
-
31
- traverse_ast(ast) do |node|
32
- if node[:type] == :legacy_function
33
- issues << { message: "Use def instead of function for #{node[:name]}", line: node[:line] || 0, column: node[:column] || 0 }
34
- end
35
- end
36
-
37
- issues
38
- end)
39
-
40
27
  # Rule: Variables should have type annotations
41
28
  register_rule(Rule.new("missing-type-annotation", "Variable declaration is missing type annotation") do |ast|
42
29
  issues = []
@@ -79,6 +66,21 @@ module Vinter
79
66
 
80
67
  issues
81
68
  end)
69
+
70
+ # Rule: should use the full name of commands that have abbreviations
71
+ register_rule(Rule.new("use-full-name", "Dont use partial names for commands") do |ast|
72
+ issues = []
73
+
74
+ traverse_ast(ast) do |node|
75
+ if node[:type] == :exec_command
76
+ unless node[:value].start_with?("execute")
77
+ issues << { message: "Use of execute command should use the full name", line: node[:line] }
78
+ end
79
+ end
80
+ end
81
+
82
+ issues
83
+ end)
82
84
  end
83
85
 
84
86
  def traverse_ast(node, &block)
data/lib/vinter/parser.rb CHANGED
@@ -408,8 +408,6 @@ module Vinter
408
408
  parse_autocmd_statement
409
409
  elsif current_token[:value] == "filter" || current_token[:value] == "filt"
410
410
  parse_filter_command
411
- elsif current_token[:value] == "command"
412
- parse_command_definition
413
411
  else
414
412
  parse_expression_statement
415
413
  end
@@ -461,6 +459,10 @@ module Vinter
461
459
  end
462
460
  elsif [:bracket_open, :bracket_close, :operator, :question_mark].include?(current_token[:type])
463
461
  advance
462
+ elsif current_token[:type] == :mode_command
463
+ advance
464
+ elsif current_token[:type] == :exec_command
465
+ advance
464
466
  else
465
467
  @warnings << {
466
468
  message: "Unexpected token type: #{current_token[:type]}",
@@ -1475,7 +1477,7 @@ module Vinter
1475
1477
  advance
1476
1478
  name += current_token[:value]
1477
1479
  end
1478
- elsif !current_token || ![:identifier, :keyword].include?(current_token[:type])
1480
+ elsif !current_token || current_token[:type] != :identifier
1479
1481
  add_error("Expected variable name: #{current_token[:type]}")
1480
1482
  return nil
1481
1483
  else
data/lib/vinter.rb CHANGED
@@ -5,5 +5,5 @@ require "vinter/cli"
5
5
  require "vinter/ast_printer"
6
6
 
7
7
  module Vinter
8
- VERSION = "0.6.6"
8
+ VERSION = "0.7.0"
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vinter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.6
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Bradbury
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-12-29 00:00:00.000000000 Z
11
+ date: 2026-01-08 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A linter for vim9script
14
14
  email: dan.luckydaisy@gmail.com