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

Support running user rule files located outside of the NsiqCppStyle package #40

Open
mosherubin opened this issue Jul 6, 2022 · 1 comment

Comments

@mosherubin
Copy link
Collaborator

mosherubin commented Jul 6, 2022

Problem Description

Currently any rule file used in an NsiqCppStyle session (e.g., RULE_3_1_A_do_not_start_filename_with_underbar) must reside in the nsiqcppstyle\rules package folder. You can see this in nsiqcppstyle_runmanager.py:

def LoadRules(self, checkingRuleNames):
    ...
    for ruleName in checkingRuleNames:
        ruleModule = __import__("rules." + ruleName)
        self.loadedRule.append(ruleModule)
    ...

I have written many proprietary rules that I do not want to return to the NsiqCppStyle repository. To include them in my NsiqCppStyle checking runs, I must copy my rules to the rules folder. Should I upgrade NsiqCppStyle to a newer version I may need to copy all of my proprietary rules again. Should I push changes through a GitHub pull request, I have to be careful not to add my proprietary rules to the commit. In general, I want to keep my proprietary rules totally separate from the NsiqCppStyle package.

Proposed Solution

The proposal is to support a new command-line option for specifying one or more additional paths that should be searched for rules. These paths can be anywhere in the file system. For all rule names in the filefilter.txt file, NsiqCppStyle should search first the rules folder, followed by any additional folders. If found, the engine should import the rule file. The following Stack Overflow post provides Python code that can be used to import the rule file from anywhere. Here is a test script I wrote:

d:\junk\import-from-anywhere\main.py

import importlib.util
import sys
spec = importlib.util.spec_from_file_location("test.py", "d:\\junk\\test.py")
foo = importlib.util.module_from_spec(spec)
sys.modules["test.py"] = foo
spec.loader.exec_module(foo)
print("foobar=%d" % (foo.foobar))

d:\junk\test.py

foobar = 5

Running main.py shows the import in action:

D:\Junk\NsiqCppStyle\Import-From-Anywhere>python main.py
foobar=5
@kunaltyagi
Copy link
Owner

+1 for this. It could allow total separation of rule and engine. Then we could have groups of rules as well instead of putting _A, _B etc. on the rules

@mosherubin mosherubin changed the title Support running user rule files outside of the NsiqCppStyle package Support running user rule files located outside of the NsiqCppStyle package Jul 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants