Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
sqlint
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nimrod
sqlint
Commits
572cbd1f
Commit
572cbd1f
authored
9 years ago
by
Kieran Trezona-le Comte
Browse files
Options
Downloads
Patches
Plain Diff
Truncate long "at or near ..." error messages
parent
5d5761b5
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
TODO
+1
-1
1 addition, 1 deletion
TODO
lib/sqlint/linter.rb
+5
-1
5 additions, 1 deletion
lib/sqlint/linter.rb
spec/linter_spec.rb
+10
-1
10 additions, 1 deletion
spec/linter_spec.rb
with
16 additions
and
3 deletions
TODO
+
1
−
1
View file @
572cbd1f
...
@@ -6,4 +6,4 @@
...
@@ -6,4 +6,4 @@
- [ ] Support for other SQL dialects
- [ ] Support for other SQL dialects
- [ ] JSON output
- [ ] JSON output
- [ ] Huge files
- [ ] Huge files
- [
] Maybe truncate long 'at or near "blah"' strings
- [
X
] Maybe truncate long 'at or near "blah"' strings
This diff is collapsed.
Click to expand it.
lib/sqlint/linter.rb
+
5
−
1
View file @
572cbd1f
...
@@ -31,7 +31,7 @@ module SQLint
...
@@ -31,7 +31,7 @@ module SQLint
rescue
PgQuery
::
ParseError
=>
e
rescue
PgQuery
::
ParseError
=>
e
offset
=
e
.
location
+
parse_state
.
offset
offset
=
e
.
location
+
parse_state
.
offset
line_number
,
column_number
=
find_absolute_position
(
offset
)
line_number
,
column_number
=
find_absolute_position
(
offset
)
lint
=
Lint
.
new
(
@filename
,
line_number
,
column_number
,
:error
,
e
.
message
)
lint
=
Lint
.
new
(
@filename
,
line_number
,
column_number
,
:error
,
clean_message
(
e
.
message
)
)
input_from_error
=
parse_state
.
input
[
e
.
location
..-
1
]
input_from_error
=
parse_state
.
input
[
e
.
location
..-
1
]
semicolon_pos
=
input_from_error
.
index
(
";"
)
if
input_from_error
semicolon_pos
=
input_from_error
.
index
(
";"
)
if
input_from_error
...
@@ -54,5 +54,9 @@ module SQLint
...
@@ -54,5 +54,9 @@ module SQLint
column_number
=
lines_before_error
.
any?
?
lines_before_error
.
last
.
size
:
1
column_number
=
lines_before_error
.
any?
?
lines_before_error
.
last
.
size
:
1
[
line_number
,
column_number
]
[
line_number
,
column_number
]
end
end
def
clean_message
(
message
)
message
.
gsub
(
/(?<=at or near ")(.*)(?=")/
)
{
|
match
|
match
[
0
..
49
]
}
end
end
end
end
end
This diff is collapsed.
Click to expand it.
spec/linter_spec.rb
+
10
−
1
View file @
572cbd1f
...
@@ -69,10 +69,19 @@ RSpec.describe SQLint::Linter do
...
@@ -69,10 +69,19 @@ RSpec.describe SQLint::Linter do
context
"when there is a second error at the end of the file"
do
context
"when there is a second error at the end of the file"
do
let
(
:input
)
{
"WIBBLE; SELECT 1 FROM"
}
let
(
:input
)
{
"WIBBLE; SELECT 1 FROM"
}
it
"report 2 errors"
do
it
"report
s
2 errors"
do
expect
(
results
).
to
eq
([
error
(
1
,
1
,
WIBBLE_ERROR
),
expect
(
results
).
to
eq
([
error
(
1
,
1
,
WIBBLE_ERROR
),
error
(
1
,
21
,
"syntax error at end of input"
)])
error
(
1
,
21
,
"syntax error at end of input"
)])
end
end
end
end
end
end
describe
"long error messages"
do
context
"when the 'at or near' fragment is longer than 50 characters"
do
let
(
:input
)
{
"SELECT '"
+
'x'
*
100
}
it
"truncates the fragment"
do
expect
(
results
).
to
eq
([
error
(
1
,
8
,
"unterminated quoted string at or near
\"
'
#{
'x'
*
49
}
\"
"
)])
end
end
end
end
end
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment