-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add ruff linter,formatter * update readme * fix ruff formatter test * add ruff --fix * Update README.md * stylua
- Loading branch information
Showing
8 changed files
with
158 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
local lint = require('guard.lint') | ||
|
||
return { | ||
cmd = 'ruff', | ||
args = { | ||
'-n', | ||
'-e', | ||
'--format', | ||
'json', | ||
'-', | ||
'--stdin-filename', | ||
}, | ||
stdin = true, | ||
fname = true, | ||
parse = lint.from_json({ | ||
attributes = { | ||
severity = 'type', | ||
lnum = function(js) | ||
return js['location']['row'] | ||
end, | ||
col = function(js) | ||
return js['location']['column'] | ||
end, | ||
}, | ||
severities = { | ||
E = lint.severities.error, -- pycodestyle errors | ||
W = lint.severities.warning, -- pycodestyle warnings | ||
F = lint.severities.info, -- pyflakes | ||
A = lint.severities.info, -- flake8-builtins | ||
B = lint.severities.warning, -- flake8-bugbear | ||
C = lint.severities.warning, -- flake8-comprehensions | ||
T = lint.severities.info, -- flake8-print | ||
U = lint.severities.info, -- pyupgrade | ||
D = lint.severities.info, -- pydocstyle | ||
M = lint.severities.into, -- Meta | ||
}, | ||
source = 'ruff', | ||
}), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
describe('ruff', function() | ||
it('can format', function() | ||
local ft = require('guard.filetype') | ||
ft('python'):fmt('ruff_fix') | ||
require('guard').setup() | ||
|
||
local formatted = require('test.formatter.helper').test_with('python', { | ||
[[import os]], | ||
[[]], | ||
[[def foo(n):]], | ||
[[ if n in (1, 2, 3):]], | ||
[[ return n + 1]], | ||
[[ a, b = 1, 2]], | ||
}) | ||
assert.are.same({ | ||
[[]], | ||
[[def foo(n):]], | ||
[[ if n in (1, 2, 3):]], | ||
[[ return n + 1]], | ||
[[ a, b = 1, 2]], | ||
}, formatted) | ||
end) | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
describe('ruff', function() | ||
it('can format', function() | ||
local ft = require('guard.filetype') | ||
ft('python'):fmt('ruff') | ||
require('guard').setup() | ||
|
||
local formatted = require('test.formatter.helper').test_with('python', { | ||
[[def foo(n):]], | ||
[[ if n in (1,2,3):]], | ||
[[ return n+1]], | ||
[[a, b = 1, 2]], | ||
[[b, a = a, b]], | ||
[[print( f"The factorial of {a} is: {foo(a)}")]], | ||
}) | ||
assert.are.same({ | ||
[[def foo(n):]], | ||
[[ if n in (1, 2, 3):]], | ||
[[ return n + 1]], | ||
[[]], | ||
[[a, b = (1, 2)]], | ||
[[b, a = a, b]], | ||
[[print(f"The factorial of {a} is: {foo(a)}")]], | ||
}, formatted) | ||
end) | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
describe('ruff', function() | ||
it('can lint', function() | ||
local helper = require('test.linter.helper') | ||
local ns = helper.namespace | ||
local ft = require('guard.filetype') | ||
ft('python'):lint('ruff') | ||
require('guard').setup() | ||
|
||
local diagnostics = helper.test_with('python', { | ||
[[import os]], | ||
[[def foo(n):]], | ||
[[ if n in (1, 2, 3):]], | ||
[[ return n + 1]], | ||
[[ a, b = 1, 2]], | ||
}) | ||
assert.are.same({ | ||
{ | ||
bufnr = 3, | ||
col = 7, | ||
end_col = 7, | ||
end_lnum = 0, | ||
lnum = 0, | ||
message = '`os` imported but unused [F401]', | ||
namespace = 1, | ||
severity = 1, | ||
source = 'ruff', | ||
}, | ||
{ | ||
bufnr = 3, | ||
col = 2, | ||
end_col = 2, | ||
end_lnum = 4, | ||
lnum = 4, | ||
message = 'Local variable `a` is assigned to but never used [F841]', | ||
namespace = 1, | ||
severity = 1, | ||
source = 'ruff', | ||
}, | ||
{ | ||
bufnr = 3, | ||
col = 5, | ||
end_col = 5, | ||
end_lnum = 4, | ||
lnum = 4, | ||
message = 'Local variable `b` is assigned to but never used [F841]', | ||
namespace = 1, | ||
severity = 1, | ||
source = 'ruff', | ||
}, | ||
}, diagnostics) | ||
end) | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters