codescene-oss / codescene-vscode

VS Code extension providing CodeScene analysis functionality.
Other
18 stars 2 forks source link

Allow an option to turn off certain warnings #12

Open zyllus17 opened 1 year ago

zyllus17 commented 1 year ago

Problem

I am writing code in Flutter and I am getting this warning all over my project.

Screenshot 2023-04-10 at 2 42 32 PM

I understand what it is trying to imply and it wants me to reduce the lines of codes in the file inside a function but Flutter/Dart is a nested type of language and it will have mulitple lines.

Solution

Please allow an option in settings.json file to turn off this warning.

sandlunds commented 1 year ago

There is the possibility of using code-health-rules.json which is a specific config file for codescene. If the warning for "Large Method" does not make sense in your project, you can disable it there. A template for the file can be generate with the command "CodeScene: create rules template" (just start typing "codescene" in the command palatte). I just tried it with this file:

{
  "usage": "Persist this file inside your repositories as .codescene/code-health-rules.json Keep the rules you want to override, remove the rest for simplicity and an easy overview.Override the code health rules by changing the default 1.0 value to a lower relative weight. A value of 0.0 disables the rule. A value of 0.5 still implies a code health hit but only at 50% of the default impact. Note that you can specify multiple rule sets and use the matching-content-path to control to which parts or languages the rules apply. This makes it possible to differentiate between test vs application code, or tailor rules to specific languages. In case multiple rule sets match a piece of content, then we prioritize the first mathcing set of rules.",
  "rule_sets": [
    {
      "matching_content_path": "**/*",
      "matching_content_path_doc": "Specify a glob pattern relative to this repo root. **/* means all code, **/*.js means just JavaScript, test/** means all code in a top-level test folder.",
      "rules": [
        {
          "name": "Large Method",
          "weight": 0.0
        }
      ]
    }
  ]
}

Setting the weight to 0.0 disables the rule. (FYI: don't set it to simply 0 as it doesn't work - will fix that).

Note that you can have multiple rule sets if you want this to apply only to a part of the code base.

zyllus17 commented 1 year ago

It creates a .codescene file which needs to be pushed into the project or added in .gitignore. Since I am working on a company project, will it be possible to add it into my local system only without pushing it to git. Like adding it to my settings.json file.

sandlunds commented 1 year ago

We might be able to add a setting that lets you point to a code-health-rules.json located outside of the repository. For now, if you simply wish to avoid modifying .gitignore, you can try adding it to .git/info/exclude in your repo which is like a personal .gitignore.

tennex-adam commented 1 year ago

I could also see this being useful at a global level (settings.json) because while I personally enjoy this type of feedback, others in all the repositories I work in may not. :smile: I'd love having the ability to have personal defaults that followed me around projects.

I do appreciate the workarounds suggested above!

jlindbergh commented 5 months ago

Hi! I know this is being late to the party, but another option now is to add a function level comment like //@CodeScene(disable: "Large Method") to the function. See more in CodeScene docs (and note that these directives don't work on function level code smells)

We'll keep this open and post here if implementing a more personalised rules configuration.