Skip to content

Commit bcba283

Browse files
committed
add clippy as lint
1 parent 9436ac2 commit bcba283

File tree

10 files changed

+109
-9
lines changed

10 files changed

+109
-9
lines changed

.clippy.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Clippy thresholds for EmmyLua Analyzer (parser/compiler project)
2+
cognitive-complexity-threshold = 50
3+
type-complexity-threshold = 150
4+
too-many-arguments-threshold = 12

.github/workflows/test.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,19 @@ jobs:
3737
- name: Run style check
3838
run: pre-commit run --all
3939

40+
clippy:
41+
name: Clippy Lint Check
42+
runs-on: ubuntu-latest
43+
steps:
44+
- name: Checkout
45+
uses: actions/checkout@v4
46+
- name: Install Rust toolchain with clippy
47+
uses: dtolnay/rust-toolchain@stable
48+
with:
49+
components: clippy
50+
- name: Run Clippy
51+
run: cargo clippy --workspace --all-targets --all-features -- -D warnings
52+
4053
test:
4154
runs-on: ubuntu-latest
4255
steps:

Cargo.toml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,67 @@ num-traits = { version = "0.2", features = ["std"] }
5353
mimalloc = "0.1.47"
5454
googletest = "0.14.2"
5555
unicode-general-category = "1.0.0"
56+
57+
# Lint configuration for the entire workspace
58+
[workspace.lints.clippy]
59+
# ==== Domain-Specific Allowances ====
60+
# These patterns are acceptable/necessary in parser/language-server projects
61+
62+
# Module inception is acceptable for AST/syntax organization
63+
module_inception = "allow"
64+
65+
# Enum variant name repetition is necessary for syntax tree clarity
66+
enum_variant_names = "allow"
67+
68+
# Parser methods often have domain-specific naming conventions
69+
wrong_self_convention = "allow"
70+
71+
# Box collections are sometimes needed for complex recursive structures
72+
box_collection = "allow"
73+
74+
# Parser constants shouldn't be confused with mathematical constants
75+
approx_constant = "allow"
76+
77+
# Complex cognitive complexity is acceptable for domain-specific logic
78+
cognitive_complexity = "allow"
79+
80+
# High type complexity threshold for domain modeling (see .clippy.toml for thresholds)
81+
type_complexity = "allow"
82+
83+
# Allow many arguments for builder patterns and comprehensive APIs
84+
too_many_arguments = "allow"
85+
86+
# ==== General Code Quality Allowances ====
87+
# Let-and-return is sometimes more readable for debugging
88+
let_and_return = "allow"
89+
90+
# Needless borrow warnings in test code are often false positives
91+
needless_borrow = "allow"
92+
93+
# Single component path imports are sometimes necessary
94+
single_component_path_imports = "allow"
95+
96+
# Bool assertion comparisons are explicit and readable
97+
bool_assert_comparison = "allow"
98+
99+
# Let unit value can be useful for side effects
100+
let_unit_value = "allow"
101+
102+
# Clone on copy can be more explicit about intent
103+
clone_on_copy = "allow"
104+
105+
# Collapsible if/match statements are sometimes more readable when separate
106+
collapsible_if = "allow"
107+
collapsible_match = "allow"
108+
109+
# Some functions need a Default implementation pattern without Default trait
110+
new_without_default = "allow"
111+
112+
# Manual implementations can be more explicit than derive
113+
manual_let_else = "allow"
114+
115+
# ==== Documentation Lints ====
116+
# Allow missing docs for internal/test functions
117+
missing_errors_doc = "allow"
118+
missing_panics_doc = "allow"
119+
undocumented_unsafe_blocks = "allow"

crates/emmylua_check/src/init.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,10 @@ pub fn collect_files(
163163
files
164164
}
165165

166-
pub fn calculate_include_and_exclude(
167-
emmyrc: &Emmyrc,
168-
ignore: Option<Vec<String>>,
169-
) -> (Vec<String>, Vec<String>, Vec<PathBuf>) {
166+
/// File patterns for workspace scanning: (include_patterns, exclude_patterns, exclude_dirs)
167+
type FilePatterns = (Vec<String>, Vec<String>, Vec<PathBuf>);
168+
169+
pub fn calculate_include_and_exclude(emmyrc: &Emmyrc, ignore: Option<Vec<String>>) -> FilePatterns {
170170
let mut include = vec!["**/*.lua".to_string(), "**/.editorconfig".to_string()];
171171
let mut exclude = Vec::new();
172172
let mut exclude_dirs = Vec::new();

crates/emmylua_check/src/output/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@ use crate::cmd_args::{OutputDestination, OutputFormat};
1212

1313
use crate::terminal_display::TerminalDisplay;
1414

15+
/// Type alias for diagnostic result channel
16+
type DiagnosticReceiver = Receiver<(FileId, Option<Vec<Diagnostic>>)>;
17+
1518
pub async fn output_result(
1619
total_count: usize,
1720
db: &DbIndex,
1821
workspace: PathBuf,
19-
mut receiver: Receiver<(FileId, Option<Vec<Diagnostic>>)>,
22+
mut receiver: DiagnosticReceiver,
2023
output_format: OutputFormat,
2124
output: OutputDestination,
2225
warnings_as_errors: bool,

crates/emmylua_code_analysis/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ include = [
1515
"resources/**",
1616
]
1717

18+
# Inherit workspace lints configuration
19+
[lints]
20+
workspace = true
21+
1822
[dependencies]
1923
# local
2024
emmylua_parser.workspace = true

crates/emmylua_doc_cli/src/init.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,10 @@ pub fn collect_files(
164164
files
165165
}
166166

167-
pub fn calculate_include_and_exclude(
168-
emmyrc: &Emmyrc,
169-
ignore: Option<Vec<String>>,
170-
) -> (Vec<String>, Vec<String>, Vec<PathBuf>) {
167+
/// File patterns for workspace scanning: (include_patterns, exclude_patterns, exclude_dirs)
168+
type FilePatterns = (Vec<String>, Vec<String>, Vec<PathBuf>);
169+
170+
pub fn calculate_include_and_exclude(emmyrc: &Emmyrc, ignore: Option<Vec<String>>) -> FilePatterns {
171171
let mut include = vec!["**/*.lua".to_string(), "**/.editorconfig".to_string()];
172172
let mut exclude = Vec::new();
173173
let mut exclude_dirs = Vec::new();

crates/emmylua_ls/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ readme = "README.md"
1010
keywords = ["emmylua", "doc", "lua"]
1111
categories = ["development-tools"]
1212

13+
# Inherit workspace lints configuration
14+
[lints]
15+
workspace = true
16+
1317
[dependencies]
1418
# local
1519
emmylua_code_analysis.workspace = true

crates/emmylua_parser/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ readme = "README.md"
1010
keywords = ["emmylua", "luals", "parser", "lua"]
1111
categories = ["development-tools", "parsing"]
1212

13+
# Inherit workspace lints configuration
14+
[lints]
15+
workspace = true
16+
1317
[dependencies]
1418
rowan.workspace = true
1519
rust-i18n.workspace = true

crates/emmylua_parser_desc/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ readme = "README.md"
1010
keywords = ["emmylua", "luals", "parser", "lua"]
1111
categories = ["development-tools", "parsing"]
1212

13+
# Inherit workspace lints configuration
14+
[lints]
15+
workspace = true
16+
1317
[dependencies]
1418
# local
1519
emmylua_parser.workspace = true

0 commit comments

Comments
 (0)