Skip to content
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

config: file type check ignores classes #852

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions libs/config/src/analyze/lints/c11_file_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ impl Lint<LintData> for LintC11FileType {
fn documentation(&self) -> &'static str {
r#"### Configuration

- **allow_no_extension**: Allow properties to not have a file extension, default is `true`.
- **allow_no_extension**: Allow properties to not have a file extension, default is `false`.

```toml
[lints.config.file_type]
options.allow_no_extension = false
options.allow_no_extension = true
```

### Example
Expand Down Expand Up @@ -114,7 +114,7 @@ impl LintRunner<LintData> for Runner {
let allow_no_extension = if let Some(toml::Value::Boolean(allow_no_extension)) = config.option("allow_no_extension") {
*allow_no_extension
} else {
true
false
};
// Arrays
if let Value::Array(values) = value {
Expand All @@ -138,6 +138,10 @@ impl LintRunner<LintData> for Runner {

fn check(name: &str, value: &Str, allow_no_extension: bool, processed: &Processed, config: &LintConfig) -> Option<Arc<dyn Code>> {
let value_str = value.value();
// Skip if it contains no backslashes, probably a class name
if !value_str.contains('\\') {
return None;
}
if name == "sound" && value_str.starts_with("db") {
return None;
}
Expand Down
8 changes: 5 additions & 3 deletions libs/config/tests/lints/c11_file_type.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
class CfgVehicles {
class MyVehicle {
model = "test.p3d";
editorPreview = "test.jgp";
wounds[] = {"would1.pac", "wound2.paa", "wound3.png"};
model = "x\mod\test.p3d";
uimodel = "x\mod\test_no_path";
editorPreview = "x\mod\test.jgp";
wounds[] = {"x\mod\would1.pac", "x\mod\wound2.paa", "x\mod\wound3.png"};
modelspecial = "class_name";
};
};
19 changes: 13 additions & 6 deletions libs/config/tests/snapshots/lints__config_error_c11_file_type.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,26 @@
source: libs/config/tests/lints.rs
expression: lint(stringify! (c11_file_type))
---
warning[L-C11ME]: a property that references a file is missing a file extension
┌─ c11_file_type.hpp:4:20
│
4 │ uimodel = "x\mod\test_no_path";
│ ^^^^^^^^^^^^^^^^^^ missing file extension


warning[L-C11UE]: a property that references a file has an unusual file type
┌─ c11_file_type.hpp:4:31
┌─ c11_file_type.hpp:5:37
│
4 │ editorPreview = "test.jgp";
│ ^^^ unusual file type
5 │ editorPreview = "x\mod\test.jgp";
│ ^^^ unusual file type
│
= note: expected file type jpg


warning[L-C11UE]: a property that references a file has an unusual file type
┌─ c11_file_type.hpp:5:57
┌─ c11_file_type.hpp:6:75
│
5 │ wounds[] = {"would1.pac", "wound2.paa", "wound3.png"};
│ ^^^ unusual file type
6 │ wounds[] = {"x\mod\would1.pac", "x\mod\wound2.paa", "x\mod\wound3.png"};
│ ^^^ unusual file type
│
= note: expected file type paa
Loading