Make style guideline warnings opt-in
This commit is contained in:
parent
f124052ce3
commit
3d5e775bf7
@ -44,6 +44,7 @@ The following options are currently available.
|
|||||||
| --- | --- | --- | --- |
|
| --- | --- | --- | --- |
|
||||||
| `enable_snippets` | `bool` | `true` | Enables snippet completion, set to false for compatibility with language clients that do not support snippets (such as ale). |
|
| `enable_snippets` | `bool` | `true` | Enables snippet completion, set to false for compatibility with language clients that do not support snippets (such as ale). |
|
||||||
| `zig_lib_path` | `?[]const u8` | `null` | zig library path, used to analyze std library imports. |
|
| `zig_lib_path` | `?[]const u8` | `null` | zig library path, used to analyze std library imports. |
|
||||||
|
| `warn_style` | `bool` | `false` | Enables warnings for style *guideline* mismatches |
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
@ -5,3 +5,7 @@ enable_snippets: bool = true,
|
|||||||
|
|
||||||
/// zig library path
|
/// zig library path
|
||||||
zig_lib_path: ?[]const u8 = null,
|
zig_lib_path: ?[]const u8 = null,
|
||||||
|
|
||||||
|
/// Whether to pay attention to style issues. This is opt-in since the style
|
||||||
|
/// guide explicitly states that the style info provided is a guideline only.
|
||||||
|
warn_style: bool = false,
|
||||||
|
54
src/main.zig
54
src/main.zig
@ -137,34 +137,36 @@ fn publishDiagnostics(handle: DocumentStore.Handle, config: Config) !void {
|
|||||||
if (is_extern)
|
if (is_extern)
|
||||||
break :blk;
|
break :blk;
|
||||||
|
|
||||||
if (func.name_token) |name_token| {
|
if (config.warn_style) {
|
||||||
const loc = tree.tokenLocation(0, name_token);
|
if (func.name_token) |name_token| {
|
||||||
|
const loc = tree.tokenLocation(0, name_token);
|
||||||
|
|
||||||
const is_type_function = switch (func.return_type) {
|
const is_type_function = switch (func.return_type) {
|
||||||
.Explicit => |node| if (node.cast(std.zig.ast.Node.Identifier)) |ident|
|
.Explicit => |node| if (node.cast(std.zig.ast.Node.Identifier)) |ident|
|
||||||
std.mem.eql(u8, tree.tokenSlice(ident.token), "type")
|
std.mem.eql(u8, tree.tokenSlice(ident.token), "type")
|
||||||
else
|
else
|
||||||
false,
|
false,
|
||||||
.InferErrorSet, .Invalid => false,
|
.InferErrorSet, .Invalid => false,
|
||||||
};
|
};
|
||||||
|
|
||||||
const func_name = tree.tokenSlice(name_token);
|
const func_name = tree.tokenSlice(name_token);
|
||||||
if (!is_type_function and !analysis.isCamelCase(func_name)) {
|
if (!is_type_function and !analysis.isCamelCase(func_name)) {
|
||||||
try diagnostics.append(.{
|
try diagnostics.append(.{
|
||||||
.range = astLocationToRange(loc),
|
.range = astLocationToRange(loc),
|
||||||
.severity = .Information,
|
.severity = .Information,
|
||||||
.code = "BadStyle",
|
.code = "BadStyle",
|
||||||
.source = "zls",
|
.source = "zls",
|
||||||
.message = "Functions should be camelCase",
|
.message = "Functions should be camelCase",
|
||||||
});
|
});
|
||||||
} else if (is_type_function and !analysis.isPascalCase(func_name)) {
|
} else if (is_type_function and !analysis.isPascalCase(func_name)) {
|
||||||
try diagnostics.append(.{
|
try diagnostics.append(.{
|
||||||
.range = astLocationToRange(loc),
|
.range = astLocationToRange(loc),
|
||||||
.severity = .Information,
|
.severity = .Information,
|
||||||
.code = "BadStyle",
|
.code = "BadStyle",
|
||||||
.source = "zls",
|
.source = "zls",
|
||||||
.message = "Type functions should be PascalCase",
|
.message = "Type functions should be PascalCase",
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user