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

4.x #487

Merged
merged 18 commits into from
Jan 17, 2024
Merged

4.x #487

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ options:
Modifications to the constant db.
prefix with: + - to add to DB, - - to remove from DB, None - to override DB
--print-rulefile Print loaded rules as a rulefile and exit
--release Run against a specific Yocto release (default: latest)
--exit-zero Always return a 0 (non-error) status code, even if lint errors are found
--version show program's version number and exit
```
Expand Down Expand Up @@ -120,6 +121,7 @@ Rules marked with **[S]** can have multiple sub-IDs
* oelint.file.inappropriatemsg - Patches with Upstream-Status: Inappropriate should provide a valid reasoning
* oelint.file.includenotfound - File to be included not found
* oelint.file.includerelpath - Require should be used instead of include
* oelint.file.inlinesuppress_na - A not applicable inline suppression has been found
* oelint.file.nospaces - Path to file should not contain spaces
* oelint.file.patchsignedoff - Patches should contain a Signed-Of-By entry
* oelint.file.requireinclude - Require should be used instead of include
Expand All @@ -145,9 +147,11 @@ Rules marked with **[S]** can have multiple sub-IDs
* oelint.task.nopythonprefix - Tasks containing shell code should NOT be prefixed with 'python' in function header
* oelint.task.order - Order of tasks **[S]**
* oelint.task.pythonprefix - Tasks containing python code should be prefixed with 'python' in function header
* oelint.var.addpylib - addpylib is only valid in .conf files
* oelint.var.bbclassextend - Use BBCLASSEXTEND when possible
* oelint.var.filesoverride - FILES:*(FILES_*) variables should not be overridden
* oelint.var.improperinherit - Warn about improperly named inherits
* oelint.var.inherit - Check the correct usage of inherit and inherit_defer ('scarthgap' release and newer)
* oelint.var.licenseremotefile - License shall be a file in remote source not a local file
* oelint.var.licensesdpx - Check for correct SPDX syntax in licenses
* oelint.var.mandatoryvar - Check for mandatory variables **[S]**
Expand Down Expand Up @@ -182,6 +186,7 @@ Rules marked with **[S]** can have multiple sub-IDs
* oelint.vars.licfileprefix - Unnecessary prefix to LIC_FILES_CHKSUM detected **[F]**
* oelint.vars.listappend - Proper append/prepend to lists **[F]**
* oelint.vars.mispell - Possible typo detected
* oelint.vars.mispell.unknown - Variable is not known from CONSTANTS, typo is unlikely
* oelint.vars.multilineident - On a multiline assignment, line indent is desirable
* oelint.vars.notneededspace - Space at the beginning of the var is not needed **[F]**
* oelint.vars.notrailingslash - Variable shall not end on a slash
Expand Down Expand Up @@ -270,6 +275,67 @@ You can find this example also in the development [source tree](https://github.c

Additional real-life examples can be found in e.g. [meta-rubygems](https://github.com/priv-kweihmann/meta-rubygems/tree/master/files/lint/oelint-custom)

### Release constrained rules

Rules can be also configured to work on specific releases of YP only, if determined not to be applicable, the rules will
be skipped during the loading process and therefore won't show up if e.g. `--print-rulefile` is used

#### Rules working up to a certain release

```python
from oelint_adv.cls_rule import Rule


class FooMagicRule(Rule):
def __init__(self):
super().__init__(id="foocorp.foo.magic",
severity="error",
message="Too much foo happening here",
valid_till_release="kirkstone")
```

Would enable the rule, but only if `--release` is set to a YP release earlier than `kirkstone`

#### Rules working from a certain release

```python
from oelint_adv.cls_rule import Rule


class FooMagicRule(Rule):
def __init__(self):
super().__init__(id="foocorp.foo.magic",
severity="error",
message="Too much foo happening here",
valid_from_release="kirkstone")
```

Would enable the rule, but only if `--release` is set to a YP release later than `kirkstone` (including `kirkstone`)

#### Enable special settings per release

```python
from oelint_adv.cls_rule import Rule


class FooMagicRule(Rule):
def __init__(self):
super().__init__(id="foocorp.foo.magic",
severity="error",
message="Too much foo happening here")

def check_release_range(self, release_range: List[str]) -> bool:
if 'kirkstone' in release_range:
self._we_are_running_on_kirkstone = True
self.Appendix.append('kirkstone')
return super().check_release_range(release_range)
```

Enables the special `Appendix` `kirkstone`, if `kirkstone` is part of the calculated `--release` list.

It also sets the variable `self._we_are_running_on_kirkstone`, which can be used as part of `check()` to
code special code paths.

## Defining a ruleset

If you pass the option `--rulefile` you could define the rules to be checked and their severity via a simple json file.
Expand Down
10 changes: 7 additions & 3 deletions docs/rule_example.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
from typing import List, Tuple

from oelint_parser.cls_stash import Stash

from oelint_adv.cls_rule import Rule


class FooMagicRule(Rule):
def __init__(self):
def __init__(self) -> None:
super().__init__(id='foocorp.foo.magic',
severity='error',
message='Too much foo happening here')

def check(self, _file, stash):
def check(self, _file: str, stash: Stash) -> List[Tuple[str, int, str]]:
res = []
items = stash.GetItemsFor(filename=_file)
for i in items:
Expand All @@ -17,7 +21,7 @@ def check(self, _file, stash):

# To provide automatic fixing capability
# add the following optional function
def fix(self, _file, stash):
def fix(self, _file: str, stash: Stash) -> List[str]:
res = []
items = stash.GetItemsFor(filename=_file)
for i in items:
Expand Down
Loading