svlint icon indicating copy to clipboard operation
svlint copied to clipboard

New Rule: Check that filename matches module/interface/package/program identifier.

Open DaveMcEwan opened this issue 2 years ago • 2 comments

Modules, interfaces, packages, and programs are often requried to be declared in their own file. A new set of rules should check, for example, that module Foo; ... endmodule lives in some/path/to/Foo.sv.

DaveMcEwan avatar Jun 07 '23 17:06 DaveMcEwan

Hello, I was trying to work on this issue but I ran into an issue with grabbing the file names. As far as I can find, none of the nodes seem to contain the filename information.

I was wondering if you have any pointers/know where I should look?

5han7anu-S avatar Mar 21 '24 20:03 5han7anu-S

let path = if let Some(x) = unwrap_locate!(node.clone()) {
    if let Some((path, _)) = syntax_tree.get_origin(&x) {
        Some(path)
    } else {
        None
    }

I got the file path from the Syntax tree, however, I am unable to get Cargo Test to pass the testcases.

As far as my understanding goes, Cargo Test modifies the input file name that is passed to the syntax rule checker. Printing out the file name:

./svlint/target/debug/build/svlint-0484465ec2310bbe/out/syntaxrules.identifier_matches_filename.pass.1of1.sv

For the pass testcase (in pass/identifier_matches_filename.sv), I have

module identifier_matches_filename;
endmodule

However, this fails, due to the editing of the filename prior to running by cargo test. Furthermore, it doesn't seem like I can edit the filename in any way for it to pass due to the periods (.) in the filename. That is to say, I cannot modify the pass testcase to be

module syntaxrules.identifier_matches_filename.pass.1of1;
endmodule

due to this being an invalid module name.

I modified build.rs (Line :380) to change the periods in the filename to underscores. This makes syntaxrules_identifier_matches_filename_pass_1of1 a valid module name and cargo test now passes for all testcases.

This is one option. Alternatively, I could turn off that specific testcase, if there is a reason for wanting to keep the periods in the test suite filenames.

5han7anu-S avatar Mar 28 '24 19:03 5han7anu-S