anbt-sql-formatter 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0bd065b8b98fe3a87257b39677bd7ed0fc78233173c0a1f1e99792cec2e9868f
4
- data.tar.gz: 999857541e0547429abb974f830fbba8ff0c31ae2284b89bfd840353e3029786
3
+ metadata.gz: 84e2831d39ea0a114b7dd67a1ad69be88df0a575f017c6e9ec16ed87cdc8597b
4
+ data.tar.gz: b7f86dd15c4c5b421035f39b4f7bff403305e1f2f0ebd84eed5644b5be57e7a2
5
5
  SHA512:
6
- metadata.gz: fc5d07dc5eb05cc96c250e865bf36f2ae7b8e11457b3850d112b75925a00ccb93f498b1fc389288de875d77292b7139464227f35fa7db56fb602498ffe07e623
7
- data.tar.gz: 276dc243eeaeab0ee353017e1f7d1bbcf6ec3e11e8b295f5a93331d4b5786f68a6725abe1ca89c81f72a53da821f318aeebde04ed2aa9eb205cfb497f256debe
6
+ metadata.gz: 9b928f9e74ae4139c3f1408c6727832e352b2f78ad5479f38eb5959817c405f936faab338620536ac7c2a94dc931e839e3e58e2b460922e64fbb8da805d74aff
7
+ data.tar.gz: b978f80c52d14d067c150e48992dc81eaafc948d1103ff12fade72bb3d1f6835af86532393e658b5856dd75ee3d3dc03cf9498a01b66379011a09ffb9adc87cc
data/CHANGELOG.md CHANGED
@@ -1,3 +1,27 @@
1
+ # 0.1.2 (2025-01-xx)
2
+
3
+ ## Breaking changes
4
+
5
+ - Changed to exclusive branching to reduce complexity (`Formatter#format_list_main_loop`).
6
+ - If you have not customized the rules, there will be no change in behavior.
7
+ - This likely applies to most users.
8
+ - If you have customized the rules such that keywords overlap between conditions of the branches,
9
+ this update may change the behavior.
10
+
11
+ ```ruby
12
+ # Example of customization that may change behavior:
13
+
14
+ custom_rule = AnbtSql::Rule.new
15
+ custom_rule.kw_nl_x << "SOME_CUSTOM_KEYWORD"
16
+ custom_rule.kw_nl_x_plus1_indent << "SOME_CUSTOM_KEYWORD"
17
+ ```
18
+
19
+ ## Improvements
20
+
21
+ - Some cleanups, formatting improvements
22
+ - cleanup: Remove encoding magic comments
23
+
24
+
1
25
  # 0.1.1 (2025-01-12)
2
26
 
3
27
  No breaking changes.
@@ -1,4 +1,3 @@
1
- # -*- encoding: utf-8 -*-
2
1
  $:.push File.expand_path("../lib", __FILE__)
3
2
  require "anbt-sql-formatter/version"
4
3
 
@@ -1,5 +1,4 @@
1
1
  #! /usr/bin/env ruby
2
- # -*- coding: utf-8 -*-
3
2
 
4
3
  begin
5
4
  require "anbt-sql-formatter/formatter"
@@ -1,5 +1,3 @@
1
- # -*- coding: utf-8 -*-
2
-
3
1
  =begin
4
2
  エスケープ文字
5
3
  =end
@@ -1,5 +1,3 @@
1
- # -*- coding: utf-8 -*-
2
-
3
1
  =begin rdoc
4
2
  AnbtSqlFormatter: SQL整形ツール. SQL文を決められたルールに従い整形します。
5
3
 
@@ -76,6 +74,7 @@ class AnbtSql
76
74
  "ORDINALITY", "OUT", "PARAMETER", "PARAMETERS", "PATH", "POSTFIX",
77
75
  "PREFIX", "PREORDER", "RAW", "READS", "RECURSIVE", "REDO",
78
76
  # ANSI SQLではないのだが とても良く使われる構文
79
- "TRUNCATE" ]
77
+ "TRUNCATE"
78
+ ]
80
79
  end
81
80
  end
@@ -1,5 +1,3 @@
1
- # -*- coding: utf-8 -*-
2
-
3
1
  =begin rdoc
4
2
  BlancoSqlFormatterException : SQL整形ツールの例外を表します。
5
3
 
@@ -1,5 +1,3 @@
1
- # -*- coding: utf-8 -*-
2
-
3
1
  require "anbt-sql-formatter/rule"
4
2
  require "anbt-sql-formatter/parser"
5
3
  require "anbt-sql-formatter/exception"
@@ -222,56 +220,47 @@ class AnbtSql
222
220
  equals_ignore_case(token.string, "UPDATE") )
223
221
  indent += 2
224
222
  index += insert_return_and_indent(tokens, index + 1, indent, "+2")
225
- end
226
223
 
227
224
  # indentを1つ増やし、キーワードの後ろで改行
228
- if @rule.kw_plus1_indent_x_nl.any?{ |kw| equals_ignore_case(token.string, kw) }
225
+ elsif @rule.kw_plus1_indent_x_nl.any?{ |kw| equals_ignore_case(token.string, kw) }
229
226
  indent += 1
230
227
  index += insert_return_and_indent(tokens, index + 1, indent)
231
- end
232
228
 
233
229
  # キーワードの前でindentを1つ減らして改行、キーワードの後ろでindentを戻して改行。
234
- if @rule.kw_minus1_indent_nl_x_plus1_indent.any?{ |kw| equals_ignore_case(token.string, kw) }
230
+ elsif @rule.kw_minus1_indent_nl_x_plus1_indent.any?{ |kw| equals_ignore_case(token.string, kw) }
235
231
  index += insert_return_and_indent(tokens, index , indent - 1)
236
232
  index += insert_return_and_indent(tokens, index + 1, indent )
237
- end
238
233
 
239
234
  # キーワードの前でindentを1つ減らして改行、キーワードの後ろでindentを戻して改行。
240
- if (equals_ignore_case(token.string, "VALUES"))
235
+ elsif (equals_ignore_case(token.string, "VALUES"))
241
236
  indent -= 1
242
237
  index += insert_return_and_indent(tokens, index, indent)
243
- end
244
238
 
245
239
  # キーワードの前でindentを1つ減らして改行
246
- if (equals_ignore_case(token.string, "END"))
240
+ elsif (equals_ignore_case(token.string, "END"))
247
241
  indent -= 1
248
242
  index += insert_return_and_indent(tokens, index, indent)
249
- end
250
243
 
251
244
  # キーワードの前で改行
252
- if @rule.kw_nl_x.any?{ |kw| equals_ignore_case(token.string, kw) }
245
+ elsif @rule.kw_nl_x.any?{ |kw| equals_ignore_case(token.string, kw) }
253
246
  index += insert_return_and_indent(tokens, index, indent)
254
- end
255
247
 
256
248
  # キーワードの前で改行, インデント+1
257
- if @rule.kw_nl_x_plus1_indent.any?{ |kw| equals_ignore_case(token.string, kw) }
249
+ elsif @rule.kw_nl_x_plus1_indent.any?{ |kw| equals_ignore_case(token.string, kw) }
258
250
  index += insert_return_and_indent(tokens, index, indent + 1)
259
- end
260
251
 
261
252
  # キーワードの前で改行。indentを強制的に0にする。
262
- if (equals_ignore_case(token.string, "UNION" ) ||
253
+ elsif (equals_ignore_case(token.string, "UNION" ) ||
263
254
  equals_ignore_case(token.string, "INTERSECT") ||
264
255
  equals_ignore_case(token.string, "EXCEPT" ) )
265
256
  indent -= 2
266
257
  index += insert_return_and_indent(tokens, index , indent)
267
258
  index += insert_return_and_indent(tokens, index + 1, indent)
268
- end
269
259
 
270
- if equals_ignore_case(token.string, "BETWEEN")
260
+ elsif equals_ignore_case(token.string, "BETWEEN")
271
261
  encounter_between = true
272
- end
273
262
 
274
- if equals_ignore_case(token.string, "AND")
263
+ elsif equals_ignore_case(token.string, "AND")
275
264
  # BETWEEN のあとのANDは改行しない。
276
265
  if not encounter_between
277
266
  index += insert_return_and_indent(tokens, index, indent)
@@ -395,7 +384,7 @@ class AnbtSql
395
384
  if $DEBUG
396
385
  $stderr.puts e.message, e.backtrace
397
386
  $stderr.puts "tokens: "
398
- tokens.each_with_index{|t,i|
387
+ tokens.each_with_index{|t, i|
399
388
  $stderr.puts "index=%d: %s" % [i, t.inspect]
400
389
  }
401
390
  $stderr.puts "index/size: %d/%d / indent: %d / opt: %s" % [index, tokens.size, indent, opt]
@@ -1,5 +1,3 @@
1
- # -*- coding: utf-8 -*-
2
-
3
1
  require "pp"
4
2
 
5
3
  require "anbt-sql-formatter/token"
@@ -67,7 +65,7 @@ class AnbtSql
67
65
  # これ以降の文字の扱いは保留
68
66
  def symbol?(c)
69
67
  %w(" ? % & ' \( \) | * + , - . / : ; < = > !).include? c
70
- #"
68
+ # "
71
69
  end
72
70
 
73
71
 
@@ -160,7 +158,7 @@ class AnbtSql
160
158
 
161
159
  # 2文字の記号かどうか調べる
162
160
  ch2 = char_at(@before, @pos)
163
- #for (int i = 0; i < two_character_symbol.length; i++) {
161
+ # for (int i = 0; i < two_character_symbol.length; i++) {
164
162
  for i in 0...@two_character_symbol.length
165
163
  if (char_at(@two_character_symbol[i], 0) == @char &&
166
164
  char_at(@two_character_symbol[i], 1) == ch2)
@@ -1,5 +1,3 @@
1
- # -*- coding: utf-8 -*-
2
-
3
1
  require "anbt-sql-formatter/helper"
4
2
 
5
3
  =begin
@@ -1,5 +1,3 @@
1
- # -*- coding: utf-8 -*-
2
-
3
1
  class AnbtSql
4
2
  class TokenConstants
5
3
 
@@ -1,7 +1,7 @@
1
1
  module Anbt
2
2
  module Sql
3
3
  module Formatter
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
6
6
  end
7
7
  end
@@ -1,5 +1,4 @@
1
1
  #! /usr/bin/ruby
2
- # -*- coding: utf-8 -*-
3
2
 
4
3
  require "pp"
5
4
 
@@ -55,8 +54,8 @@ if $0 == __FILE__
55
54
  rule.function_names << func_name.upcase
56
55
  }
57
56
 
58
- #rule.indent_string = " "
59
- #rule.indent_string = "('-')"
57
+ # rule.indent_string = " "
58
+ # rule.indent_string = "('-')"
60
59
  rule.indent_string = "| "
61
60
 
62
61
  formatter = AnbtSql::Formatter.new(rule)
data/test/helper.rb CHANGED
@@ -12,8 +12,8 @@ class Helper
12
12
  end
13
13
 
14
14
 
15
- def assert_equals(a,b,c)
16
- assert_equal(b,c,a)
15
+ def assert_equals(a, b, c)
16
+ assert_equal(b, c, a)
17
17
  end
18
18
 
19
19
  def strip_indent(text)
@@ -1,5 +1,3 @@
1
- # -*- coding: utf-8 -*-
2
-
3
1
  require File.join(File.expand_path(File.dirname(__FILE__)), "helper")
4
2
 
5
3
  require "anbt-sql-formatter/coarse-tokenizer"
@@ -1,5 +1,3 @@
1
- # -*- coding: utf-8 -*-
2
-
3
1
  require File.join(File.expand_path(File.dirname(__FILE__)), "helper")
4
2
 
5
3
  require "anbt-sql-formatter/formatter"
data/test/test_helper.rb CHANGED
@@ -1,5 +1,3 @@
1
- # -*- coding: utf-8 -*-
2
-
3
1
  require File.join(File.expand_path(File.dirname(__FILE__)), "helper")
4
2
 
5
3
  require "anbt-sql-formatter/helper"
@@ -1,5 +1,3 @@
1
- # -*- coding: utf-8 -*-
2
-
3
1
  require File.join(File.expand_path(File.dirname(__FILE__)), "helper")
4
2
 
5
3
  require "anbt-sql-formatter/formatter"
data/test/test_parser.rb CHANGED
@@ -1,5 +1,3 @@
1
- # -*- coding: utf-8 -*-
2
-
3
1
  require File.join(File.expand_path(File.dirname(__FILE__)), "helper")
4
2
 
5
3
  require "anbt-sql-formatter/rule"
data/test/test_rule.rb CHANGED
@@ -1,5 +1,3 @@
1
- # -*- coding: utf-8 -*-
2
-
3
1
  require File.join(File.expand_path(File.dirname(__FILE__)), "helper")
4
2
 
5
3
  require "anbt-sql-formatter/helper"
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: anbt-sql-formatter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - sonota88
8
+ autorequire:
8
9
  bindir: bin
9
10
  cert_chain: []
10
- date: 2025-01-12 00:00:00.000000000 Z
11
+ date: 2025-01-26 00:00:00.000000000 Z
11
12
  dependencies:
12
13
  - !ruby/object:Gem::Dependency
13
14
  name: test-unit
@@ -66,6 +67,7 @@ files:
66
67
  homepage: https://github.com/sonota88/anbt-sql-formatter
67
68
  licenses: []
68
69
  metadata: {}
70
+ post_install_message:
69
71
  rdoc_options: []
70
72
  require_paths:
71
73
  - lib
@@ -80,7 +82,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
82
  - !ruby/object:Gem::Version
81
83
  version: '0'
82
84
  requirements: []
83
- rubygems_version: 3.6.2
85
+ rubygems_version: 3.4.19
86
+ signing_key:
84
87
  specification_version: 4
85
88
  summary: A tool for SQL formatting written in Ruby.
86
89
  test_files: []