Skip to content

Commit 689118d

Browse files
authored
Merge pull request #707 from taminomara/codestyle
Add linting for trailing whitespaces, newline symbols, etc.
2 parents 0250a57 + eefdd38 commit 689118d

File tree

83 files changed

+553
-467
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+553
-467
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,13 @@ jobs:
8181
- name: Upload
8282
if: ${{ matrix.cross != 'zigbuild' }}
8383
uses: actions/upload-artifact@v4
84-
with:
84+
with:
8585
name: ${{ matrix.crate }}-${{ matrix.platform }}
8686
path: ${{ github.workspace }}/artifact/
8787
- name: Upload zigbuild
8888
if: ${{ matrix.cross == 'zigbuild' }}
8989
uses: actions/upload-artifact@v4
90-
with:
90+
with:
9191
name: ${{ matrix.crate }}-${{ matrix.platform }}-glibc.${{ matrix.glibc }}
9292
path: ${{ github.workspace }}/artifact/
9393
release:
@@ -136,7 +136,7 @@ jobs:
136136
7z a emmylua_doc_cli-win32-x64.zip emmylua_doc_cli.exe
137137
- name: Release
138138
uses: softprops/action-gh-release@v2
139-
with:
139+
with:
140140
name: emmylua_ls
141141
draft: false
142142
generate_release_notes: true

.github/workflows/test.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,17 @@ jobs:
2525
uses: crate-ci/typos@master
2626

2727
reformat:
28-
name: Rustfmt
28+
name: Code Style Check
2929
runs-on: ubuntu-latest
3030
steps:
3131
- name: Checkout
3232
uses: actions/checkout@v4
3333
- name: Install Rust toolchain
3434
uses: dtolnay/rust-toolchain@stable
35-
- name: Run Rustfmt
36-
run: cargo fmt --all -- --check
35+
- name: Install pre-commit
36+
run: pip install pre-commit
37+
- name: Run style check
38+
run: pre-commit run --all
3739

3840
test:
3941
runs-on: ubuntu-latest

.github/workflows/upload_cachix.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ jobs:
1717
- nixos-24.11 # remove this when 25.05 is out of beta
1818
- nixos-unstable
1919
- nixpkgs-unstable
20-
20+
2121
runs-on: ubuntu-latest
2222
steps:
2323
- name: Clone repo
2424
uses: actions/checkout@v4
25-
25+
2626
- name: Setup Nix
2727
uses: cachix/install-nix-action@v30
2828
with:
@@ -34,13 +34,13 @@ jobs:
3434
- name: Show the current nixpkgs version
3535
run: |
3636
nix eval --impure --raw --expr '"Building for nixpkgs " + (import <nixpkgs> { }).lib.version'
37-
37+
3838
- name: Setup Cachix
3939
uses: cachix/cachix-action@v15
4040
with:
4141
name: emmylua-analyzer
4242
authToken: '${{ secrets.CACHIX }}'
43-
43+
4444
- name: Build emmylua-analyzer
4545
run: |
4646
for x in emmylua_{ls,doc_cli,check}; do

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
/target
22
.idea
33
.cursor
4-
dhat-heap.json
4+
dhat-heap.json

.pre-commit-config.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
repos:
2+
- repo: local
3+
hooks:
4+
- id: fmt
5+
name: fmt
6+
description: run cargo fmt
7+
entry: cargo fmt
8+
language: system
9+
types: [ rust ]
10+
args: [ "--all" ]
11+
pass_filenames: false
12+
- repo: https://github.com/pre-commit/pre-commit-hooks
13+
rev: v6.0.0
14+
hooks:
15+
- id: trailing-whitespace
16+
- id: end-of-file-fixer
17+
- id: fix-byte-order-marker
18+
- id: mixed-line-ending
19+
args: [ --fix=lf ]
20+
- id: check-added-large-files
21+
- id: check-yaml
22+
- id: check-toml
23+
- id: check-json
24+
exclude: ^.vscode/
25+
- id: check-merge-conflict
26+
- id: check-shebang-scripts-are-executable
27+
exclude_types: [ rust ]
28+
- id: check-symlinks
29+
- id: destroyed-symlinks
30+
- id: check-vcs-permalinks

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@
3030
"cwd": "${workspaceFolder}"
3131
},
3232
]
33-
}
33+
}

.vscode/settings.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
{}
1+
{
2+
"files.eol": "\n",
3+
"files.insertFinalNewline": true,
4+
"files.trimFinalNewlines": true,
5+
"files.trimTrailingWhitespace": true,
6+
"files.trimTrailingWhitespaceInRegexAndStrings": true
7+
}

CHANGELOG.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ Note: The built-in formatter is not stylua, but emmyluacodestyle. This feature s
9393
---@param f1 fun(...: T...): any
9494
---@param ... T...
9595
function invoke(f1, ...)
96-
96+
9797
end
9898

9999
invoke(function(a, b, c) -- infer as: integer, integer, integer
@@ -279,7 +279,7 @@ Also supports immutability checks for iterator variables in for loop statements.
279279
## [0.8.0] - 2025-5-30
280280

281281
### ✨ Added
282-
- **New Standard Types**:
282+
- **New Standard Types**:
283283
- `std.Unpack` type for better `unpack` function inference
284284
- `std.Rawget` type for better `rawget` function inference
285285
- **Generator Support**: Implementation similar to `luals`
@@ -397,7 +397,7 @@ Global configuration have less priority than the local one
397397
- **Flow Analyze Algorithm**: Refactor flow analyze algorithm
398398

399399
### 🐛 Fixed
400-
- **Self Inference**: Fix some self infer issue
400+
- **Self Inference**: Fix some self infer issue
401401
- **Diagnostic Action**: Fix some diagnostic action issue
402402
- **Type Check and Completion**: Optimize some type check and completion
403403

@@ -429,7 +429,7 @@ Global configuration have less priority than the local one
429429

430430
### ✨ Added
431431
- **Re-index Control**: Disable re-index in default, need to enable by `workspace.enableReindex`
432-
- **New Diagnostics**: Add New Diagnostics `inject_field`, `missing_fields`, `redefined_local`, `undefined_field`, `inject-field`, `missing-global-doc`,
432+
- **New Diagnostics**: Add New Diagnostics `inject_field`, `missing_fields`, `redefined_local`, `undefined_field`, `inject-field`, `missing-global-doc`,
433433
`incomplete-signature-doc`, `circle-doc-class`, `assign-type-mismatch`, `unbalanced_assignments`, `check_return_count`, `duplicate_require`, `circle_doc_class`, `incomplete_signature_doc`, `unnecessary_assert`
434434
- **Boolean Type Support**: Support `true` and `false` as type
435435
- **Compact Fun Return Syntax**: Compact luals fun return syntax like: `(name: string, age: number)`
@@ -497,7 +497,7 @@ Global configuration have less priority than the local one
497497
```
498498
- **Enum Type Check Fix**: Fix enum type check
499499
- **Custom Operator Infer Fix**: Fix custom operator infer
500-
- **Select Function Fix and Std.Select Type Addition**: Fix select function and add std.Select type
500+
- **Select Function Fix and Std.Select Type Addition**: Fix select function and add std.Select type
501501
- **Union Type Refactor**: Refactor Union type
502502
- **Description Support for Type**: Add description to type
503503
- **Multi Union Description Support**: Support description without '#' on multi union
@@ -541,7 +541,7 @@ Global configuration have less priority than the local one
541541

542542
---
543543

544-
## [0.4.6]
544+
## [0.4.6]
545545

546546
### 🐛 Fixed
547547
- **Executable File Directory Hierarchy Issue**: Fix issue with executable file directory hierarchy being too deep.

CONTRIBUTING.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Contributing
2+
3+
## Crates Overview
4+
5+
Our project is organized into several crates:
6+
7+
| Crate | Badge | Description |
8+
|----------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------| ----------- |
9+
| [🔍 **emmylua_parser**](./crates/emmylua_parser) | [![emmylua_parser](https://img.shields.io/crates/v/emmylua_parser.svg?style=flat-square)](https://crates.io/crates/emmylua_parser) | The foundational Rust-based Lua parser engineered for maximum efficiency and accuracy. Powers all downstream analysis tools. |
10+
| [📑 **emmylua_parser_desc**](./crates/emmylua_parser_desc) | [![emmylua_parser_desc](https://img.shields.io/crates/v/emmylua_parser_desc.svg?style=flat-square)](https://crates.io/crates/emmylua_parser_desc) | Extension for EmmyLua-Parser that handles Markdown/RST highlighting in comments. |
11+
| [🧠 **emmylua_code_analysis**](./crates/emmylua_code_analysis) | [![emmylua_code_analysis](https://img.shields.io/crates/v/emmylua_code_analysis.svg?style=flat-square)](https://crates.io/crates/emmylua_code_analysis) | Advanced semantic analysis engine providing deep code understanding, type inference, and cross-reference resolution. |
12+
| [🖥️ **emmylua_ls**](./crates/emmylua_ls) | [![emmylua_ls](https://img.shields.io/crates/v/emmylua_ls.svg?style=flat-square)](https://crates.io/crates/emmylua_ls) | The complete Language Server Protocol implementation offering rich IDE features across all major editors. |
13+
| [📚 **emmylua_doc_cli**](./crates/emmylua_doc_cli/) | [![emmylua_doc_cli](https://img.shields.io/crates/v/emmylua_doc_cli.svg?style=flat-square)](https://crates.io/crates/emmylua_doc_cli) | Professional documentation generator creating beautiful, searchable API docs from your Lua code and annotations. |
14+
| [**emmylua_check**](./crates/emmylua_check) | [![emmylua_check](https://img.shields.io/crates/v/emmylua_check.svg?style=flat-square)](https://crates.io/crates/emmylua_check) | Comprehensive static analysis tool for code quality assurance, catching bugs before they reach production. |
15+
16+
17+
## Testing
18+
19+
We use the standard Rust testing harness, along with assert macros from [`googletest-rust`]:
20+
21+
```shell
22+
# Run all tests
23+
cargo test
24+
25+
# Run tests for specific crate
26+
cargo test -p emmylua_parser
27+
```
28+
29+
If you're unfamiliar with `googletest-rust`, here's a quick overview:
30+
31+
- Use `googletest::prelude::*` in your test modules, and annotate test functions with `#[gtest]`.
32+
33+
- `assert_that!` checks a condition and panics on error:
34+
35+
```rust
36+
assert_that!(2 * 2, eq(4));
37+
```
38+
39+
Prefer `assert_that!(x, eq(y))` to `assert_eq` because the former generates a nice diff for you.
40+
41+
- `expect_that!` checks a condition, marks test as failed on error, and continues execution.
42+
43+
This is useful when adding multiple test cases to a single `#[gtest]` function:
44+
45+
```rust
46+
// Both expectations will be evaluated and reported when test fails:
47+
expect_that!(2 * 2, ne(4));
48+
expect_that!(3 * 3, ne(9));
49+
```
50+
51+
- `verify_that!` checks a condition and returns a `googletest::Result`.
52+
53+
- `OrFail::or_fail` converts any `Optional` and `Result` to a `googletest::Result`. It also adds current location
54+
to an error message. We have a wrapper around it called [`check!`].
55+
56+
57+
## Code style and formatting
58+
59+
We use [`rustfmt`] and [`pre-commit`] to manage project's code style.
60+
61+
- `rustfmt` formats Rust code. Simply run `cargo fmt --all` to reformat all files.
62+
63+
- `pre-commit` fixes common issues like trailing whitespaces or broken symlinks in all text files.
64+
65+
To run it,
66+
67+
1. install [`pre-commit`][pre-commit-install],
68+
2. invoke `pre-commit run --all`.
69+
70+
If it suits your workflow, you can configure PreCommit to run before every commit. To do so, run `pre-commit install`.
71+
Note that this is not required because our CI will detect any issues.
72+
73+
[`googletest-rust`]: https://github.com/google/googletest-rust/
74+
[`rustfmt`]: https://rust-lang.github.io/rustfmt/
75+
[`pre-commit`]: https://pre-commit.com/#install
76+
[pre-commit-install]: https://pre-commit.com/#install
77+
[`check!`]: https://github.com/search?q=repo%3AEmmyLuaLs%2Femmylua-analyzer-rust%20macro_rules!%20check&type=code

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ emmylua_diagnostic_macro = { path = "crates/emmylua_diagnostic_macro", version =
1515
# external
1616
lsp-server = "0.7.7"
1717
tokio = { version = "1.46", features = ["full"] }
18-
serde = { version = "1.0.219", features = ["derive"] }
18+
serde = { version = "1.0.219", features = ["derive"] }
1919
serde_json = "1.0.141"
2020
rowan = { version = "0.16.1" }
2121
notify = { version = "8.1.0", features = ["serde"] }

0 commit comments

Comments
 (0)