-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check for file name capitalization in the presence of top level fields.
- Loading branch information
Showing
11 changed files
with
100 additions
and
3 deletions.
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,33 @@ | ||
//! Check for file name capitalization in the presence of top level fields. | ||
|
||
const std = @import("std"); | ||
const analysis = @import("../analysis.zig"); | ||
|
||
pub const FileAsStruct = struct { | ||
pub fn check_tree( | ||
self: *FileAsStruct, | ||
allocator: std.mem.Allocator, | ||
fault_tracker: *analysis.SourceCodeFaultTracker, | ||
file_name: []const u8, | ||
tree: std.zig.Ast, | ||
) !void { | ||
_ = self; | ||
_ = allocator; | ||
|
||
const tags = tree.nodes.items(.tag); | ||
const rootDecls = tree.rootDecls(); | ||
|
||
const has_top_level_fields = for (rootDecls) |item| { | ||
if (tags[item].isContainerField()) break true; | ||
} else false; | ||
|
||
const capitalized = std.ascii.isUpper(std.fs.path.basename(file_name)[0]); | ||
if (has_top_level_fields != capitalized) { | ||
try fault_tracker.add(analysis.SourceCodeFault{ | ||
.line_number = 1, | ||
.column_number = 1, | ||
.fault_type = .{ .FileAsStruct = !capitalized }, | ||
}); | ||
} | ||
} | ||
}; |
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,3 @@ | ||
export fn foo(bar: u32) u32 { | ||
return bar + 64; | ||
} |
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,2 @@ | ||
foo: u32, | ||
bar: f64, |
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 @@ | ||
2 |
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,3 @@ | ||
export fn foo(bar: u32) u32 { | ||
return bar + 64; | ||
} |
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,2 @@ | ||
./struct.zig:1:1: found top level fields, file name should be capitalized | ||
./NotStruct.zig:1:1: found no top level fields, file name should be lowercase |
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,2 @@ | ||
foo: u32, | ||
bar: f64, |
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,3 @@ | ||
{ | ||
"file_as_struct": true | ||
} |