Skip to content

Commit 27532e2

Browse files
committed
move variable naming checks to diagnostics.zig
1 parent 628f715 commit 27532e2

2 files changed

Lines changed: 14 additions & 16 deletions

File tree

src/analysis.zig

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -655,20 +655,6 @@ pub fn isTypeFunction(tree: *const Ast, func: Ast.full.FnProto) bool {
655655
return isMetaType(tree, return_type);
656656
}
657657

658-
// STYLE
659-
660-
pub fn isCamelCase(name: []const u8) bool {
661-
return !std.ascii.isUpper(name[0]) and !isSnakeCase(name);
662-
}
663-
664-
pub fn isPascalCase(name: []const u8) bool {
665-
return std.ascii.isUpper(name[0]) and !isSnakeCase(name);
666-
}
667-
668-
pub fn isSnakeCase(name: []const u8) bool {
669-
return std.mem.find(u8, name, "_") != null;
670-
}
671-
672658
// ANALYSIS ENGINE
673659

674660
/// Resolves variable declarations consisting of chains of imports and field accesses of containers

src/features/diagnostics.zig

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,15 +206,15 @@ fn collectWarnStyleDiagnostics(
206206
const is_type_function = Analyser.isTypeFunction(tree, func);
207207

208208
const func_name = tree.tokenSlice(name_token);
209-
if (!is_type_function and !Analyser.isCamelCase(func_name)) {
209+
if (!is_type_function and !isCamelCase(func_name)) {
210210
try diagnostics.append(arena, .{
211211
.range = offsets.tokenToRange(tree, name_token, offset_encoding),
212212
.severity = .Hint,
213213
.code = .{ .string = "bad_style" },
214214
.source = "zls",
215215
.message = "Functions should be camelCase",
216216
});
217-
} else if (is_type_function and !Analyser.isPascalCase(func_name)) {
217+
} else if (is_type_function and !isPascalCase(func_name)) {
218218
try diagnostics.append(arena, .{
219219
.range = offsets.tokenToRange(tree, name_token, offset_encoding),
220220
.severity = .Hint,
@@ -231,6 +231,18 @@ fn collectWarnStyleDiagnostics(
231231
}
232232
}
233233

234+
fn isCamelCase(name: []const u8) bool {
235+
return !std.ascii.isUpper(name[0]) and !isSnakeCase(name);
236+
}
237+
238+
fn isPascalCase(name: []const u8) bool {
239+
return std.ascii.isUpper(name[0]) and !isSnakeCase(name);
240+
}
241+
242+
fn isSnakeCase(name: []const u8) bool {
243+
return std.mem.find(u8, name, "_") != null;
244+
}
245+
234246
fn collectGlobalVarDiagnostics(
235247
tree: *const Ast,
236248
arena: std.mem.Allocator,

0 commit comments

Comments
 (0)