-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(linter): add line-length
rule
#232
Conversation
btw, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! Some requested changes are blocked by things I need to do, which I'll add now. Please make sure you add docs, then run just ready
and commit the changes.
src/linter/rules/line_length.zig
Outdated
} | ||
|
||
pub fn runOnLine(_: *const LineLength, line: Line, ctx: *LinterContext) void { | ||
if (line.text.len < 120) return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add this to the rule as a field const LineLength = struct { max_length: u32 = 120 }
, that way when I add rule-specific configs it will just work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really sure where you would like me to put this/ how to get this value inside the runOnce
function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check UnsafeUndefined
for an example. it's config is set inside the struct itself.
pub const LineLength = struct {
max_length: u32 = 120,
};
Then in runOnce
:
pub fn runOnce(self: *const LineLength, ctx: *LinterContext) void {
const len = getLineLength();
if (len < self.max_len) { ... }
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe I added this properly, but I can't really test it. How would a zlint.json
with an option for unsafe-undefined
look like?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eventually (not now):
{
"rules": {
"max-lines": ["warn", { "max-length": 100 }]
}
}
Yeah, sorry, that was probably due to Bun. It failed silently so I didn't realize. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #232 +/- ##
==========================================
+ Coverage 86.72% 86.76% +0.04%
==========================================
Files 69 70 +1
Lines 4640 4671 +31
==========================================
+ Hits 4024 4053 +29
- Misses 616 618 +2 ☔ View full report in Codecov by Sentry. |
src/linter/lint_context.zig
Outdated
@@ -255,6 +255,7 @@ const std = @import("std"); | |||
const mem = std.mem; | |||
const util = @import("util"); | |||
const _rule = @import("rule.zig"); | |||
const _span = @import("../span.zig"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove dead code (zlint --fix-dangerously)
line-length
ruleline-length
rule
undo line struct commit (not used) remove Line from span.zig (not needed) removed more unused imports from line_length.zig
f24e6c4
to
008d01d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once spans are fixed we can merge this. They should cover the entire line, not just characters >= the max length.
I see that the tests in Windows are breaking. The rule takes into account that the newline in windows would be "\r\n", but that's probably not the case here, making it so I've made it so the type of newline being used is detected using the first line in the file. |
That's a much better solution, since that will work on git bash. Thank you! |
The idea of this PR is to add a rule that checks if the line length is below a given threshold. Currently this PR only shows a warning if there is a line with more than 120 columns (hardcoded), without specifying which line.