Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Guideline recategorization #68

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

Merged
merged 43 commits into from
Dec 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
8647dd4
Add rule category to rule meta data
rvermeulen Aug 19, 2022
aa0a835
Add support for guideline recategorizations
rvermeulen Aug 23, 2022
ebf64e6
Move coding standards config processing script
rvermeulen Aug 24, 2022
86bc3f8
Format generated exclusion files
rvermeulen Aug 25, 2022
8738fe1
Add support for generating files for multiple packages
rvermeulen Aug 25, 2022
1d4b947
Address incorrect format exclusion files
rvermeulen Aug 25, 2022
aeab8c3
Switch to GH managed CodeQL cli
rvermeulen Aug 25, 2022
acb0ff1
Address race condition in package file generation
rvermeulen Aug 25, 2022
0bdf011
Address incorrect formatting
rvermeulen Aug 29, 2022
9edb1da
Use the effective category in the exclusion process
rvermeulen Aug 29, 2022
c33952e
Add `isExcluded/3` that includes the reason for exclusion
rvermeulen Aug 30, 2022
61c33be
Exclude queries with effective category disapplied.
rvermeulen Aug 30, 2022
703c3e9
Add test case for disapplied queries.
rvermeulen Aug 30, 2022
87d7d82
Add guideline recategorization post processing script
rvermeulen Oct 14, 2022
a4d2e3a
Add tag with original category
rvermeulen Oct 25, 2022
a0a40cd
Handle schema validation exception
rvermeulen Nov 2, 2022
8b7be75
Properly handle json and yml decoding errors.
rvermeulen Nov 2, 2022
4f18053
Add unit tests for the recategorization script.
rvermeulen Nov 2, 2022
4c5407b
Add workflow to run recategorize tests
rvermeulen Nov 2, 2022
8e91bcc
Add missing deviation analysis report tables
rvermeulen Nov 4, 2022
993e1b2
Format fixes
rvermeulen Nov 4, 2022
a759166
Add guideline recategorization plan description
rvermeulen Nov 4, 2022
ea455ed
Address CodeQL module import issues
rvermeulen Nov 4, 2022
3a480e9
Include the original rule category.
rvermeulen Nov 5, 2022
7272744
Remove unused imports
rvermeulen Nov 5, 2022
bc46b75
Address incorrect type annotations
rvermeulen Nov 5, 2022
c5ea428
Address returning CSV reader on closed file
rvermeulen Nov 5, 2022
81240ca
Add create database method
rvermeulen Nov 5, 2022
30a47e0
Add guideline recategorization report generation
rvermeulen Nov 5, 2022
77b5611
Add unit test for guideline recategorization report generation
rvermeulen Nov 5, 2022
9e1be4d
Add distinguishing icon to tooling unit tests workflow
rvermeulen Nov 5, 2022
5571453
Add analysis report unit tests to testing workflow
rvermeulen Nov 5, 2022
40f8ee6
Add minimal test case for deviation report generation
rvermeulen Nov 7, 2022
cbd2fcf
Add shared components to code scanning pack
rvermeulen Nov 7, 2022
79839c4
Add guideline recategorization scripts to code scanning pack
rvermeulen Nov 7, 2022
ea3f111
Add changenote for guideline recategorization scripts
rvermeulen Nov 7, 2022
fab2b27
Add guideline recategorization design document.
rvermeulen Nov 28, 2022
a85c6ff
Clarify the category of non Misra standard guidelines.
rvermeulen Nov 29, 2022
60b3115
Apply wording suggestion from code review
rvermeulen Nov 30, 2022
36b466e
Remove remnant of the GRP proposal
rvermeulen Nov 30, 2022
097d091
Update the TOC
rvermeulen Nov 30, 2022
bdbaa07
Update document management section
rvermeulen Nov 30, 2022
be60c7b
Clarify GRP for non-MISRA standards
rvermeulen Nov 30, 2022
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
2 changes: 1 addition & 1 deletion 2 .github/workflows/code-scanning-pack-gen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ jobs:
codeql query compile --search-path c --search-path cpp --threads 0 c

cd ..
zip -r codeql-coding-standards/code-scanning-cpp-query-pack.zip codeql-coding-standards/c/ codeql-coding-standards/cpp/ codeql-coding-standards/.codeqlmanifest.json codeql-coding-standards/supported_codeql_configs.json codeql-coding-standards/scripts/deviations codeql-coding-standards/scripts/reports
zip -r codeql-coding-standards/code-scanning-cpp-query-pack.zip codeql-coding-standards/c/ codeql-coding-standards/cpp/ codeql-coding-standards/.codeqlmanifest.json codeql-coding-standards/supported_codeql_configs.json codeql-coding-standards/scripts/configuration codeql-coding-standards/scripts/reports codeql-coding-standards/scripts/shared codeql-coding-standards/scripts/guideline_recategorization codeql-coding-standards/scripts/shared codeql-coding-standards/scripts/schemas

- name: Upload GHAS Query Pack
uses: actions/upload-artifact@v2
Expand Down
91 changes: 91 additions & 0 deletions 91 .github/workflows/tooling-unit-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: 🧰 Tooling unit tests

on:
push:
branches:
- main
- "rc/**"
- next
pull_request:
branches:
- main
- "rc/**"
- next

jobs:
prepare-supported-codeql-env-matrix:
name: Prepare supported CodeQL environment matrix
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.export-supported-codeql-env-matrix.outputs.matrix }}
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Export supported CodeQL environment matrix
id: export-supported-codeql-env-matrix
run: |
echo "::set-output name=matrix::$(
jq --compact-output '.supported_environment | {include: .}' supported_codeql_configs.json
)"

analysis-report-tests:
name: Run analysis report tests
needs: prepare-supported-codeql-env-matrix
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.prepare-supported-codeql-env-matrix.outputs.matrix) }}
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Install Python
uses: actions/setup-python@v4
with:
python-version: "3.9"

- name: Install Python dependencies
run: pip install -r scripts/reports/requirements.txt

- name: Cache CodeQL
id: cache-codeql
uses: actions/cache@v2.1.3
with:
path: ${{ github.workspace }}/codeql_home
key: codeql-home-${{ matrix.os }}-${{ matrix.codeql_cli }}-${{ matrix.codeql_standard_library }}

- name: Install CodeQL
if: steps.cache-codeql.outputs.cache-hit != 'true'
uses: ./.github/actions/install-codeql
with:
codeql-cli-version: ${{ matrix.codeql_cli }}
codeql-stdlib-version: ${{ matrix.codeql_standard_library }}
codeql-home: ${{ github.workspace }}/codeql_home
add-to-path: false

- name: Run PyTest
env:
CODEQL_HOME: ${{ github.workspace }}/codeql_home
run: |
PATH=$PATH:$CODEQL_HOME/codeql
pytest scripts/reports/analysis_report_test.py

recategorization-tests:
name: Run Guideline Recategorization tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Install Python
uses: actions/setup-python@v4
with:
python-version: "3.9"

- name: Install Python dependencies
run: pip install -r scripts/guideline_recategorization/requirements.txt

- name: Run PyTest
run: |
pytest scripts/guideline_recategorization/recategorize_test.py
26 changes: 18 additions & 8 deletions 26 .github/workflows/validate-coding-standards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ jobs:
with:
python-version: "3.9"

- name: Install CodeQL
rvermeulen marked this conversation as resolved.
Show resolved Hide resolved
run: |
VERSION="v$( jq -r '.supported_environment | .[0] | .codeql_cli' supported_codeql_configs.json)"
gh extensions install github/gh-codeql
gh codeql set-version "$VERSION"
gh codeql install-stub
env:
GITHUB_TOKEN: ${{ github.token }}

- name: Install generate_package_files.py dependencies
run: pip install -r scripts/requirements.txt

Expand All @@ -49,14 +58,14 @@ jobs:

- name: Validate Package Files (CPP)
run: |
find rule_packages/cpp -name \*.json -exec basename {} .json \; | xargs --max-procs "$XARGS_MAX_PROCS" --max-args 1 python scripts/generate_rules/generate_package_files.py cpp
find rule_packages/cpp -name \*.json -exec basename {} .json \; | xargs python scripts/generate_rules/generate_package_files.py cpp
git diff
git diff --compact-summary
git diff --quiet

- name: Validate Package Files (C)
run: |
find rule_packages/c -name \*.json -exec basename {} .json \; | xargs --max-procs "$XARGS_MAX_PROCS" --max-args 1 python scripts/generate_rules/generate_package_files.py c
find rule_packages/c -name \*.json -exec basename {} .json \; | xargs python scripts/generate_rules/generate_package_files.py c
git diff
git diff --compact-summary
git diff --quiet
Expand All @@ -68,25 +77,26 @@ jobs:
- name: Checkout
uses: actions/checkout@v2

- name: Fetch CodeQL
- name: Install CodeQL
run: |
TAG="v$( jq -r '.supported_environment | .[0] | .codeql_cli' supported_codeql_configs.json)"
gh release download $TAG --repo https://github.com/github/codeql-cli-binaries --pattern codeql-linux64.zip
unzip -q codeql-linux64.zip
VERSION="v$( jq -r '.supported_environment | .[0] | .codeql_cli' supported_codeql_configs.json)"
gh extensions install github/gh-codeql
gh codeql set-version "$VERSION"
gh codeql install-stub
env:
GITHUB_TOKEN: ${{ github.token }}

- name: Validate CodeQL Format (CPP)
run: |
find cpp -name \*.ql -or -name \*.qll -print0 | xargs -0 --max-procs "$XARGS_MAX_PROCS" codeql/codeql query format --in-place
find cpp -name \*.ql -or -name \*.qll -print0 | xargs -0 --max-procs "$XARGS_MAX_PROCS" codeql query format --in-place

git diff
git diff --compact-summary
git diff --quiet

- name: Validate CodeQL Format (C)
run: |
find c -name \*.ql -or -name \*.qll -print0 | xargs -0 --max-procs "$XARGS_MAX_PROCS" codeql/codeql query format --in-place
find c -name \*.ql -or -name \*.qll -print0 | xargs -0 --max-procs "$XARGS_MAX_PROCS" codeql query format --in-place

git diff
git diff --compact-summary
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Add the Python scripts under `scripts/guideline_recategorization` and the JSON schemas under `schemas`.
- Add the Python scripts under `scripts/shared` relied upon by the analysis report generation.
32 changes: 32 additions & 0 deletions 32 cpp/common/src/codingstandards/cpp/Config.qll
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* A module for runtime configuration settings specified in a `conding-standards.yml` file.
*/

import cpp
import semmle.code.cpp.XML
import codingstandards.cpp.exclusions.RuleMetadata
import codingstandards.cpp.deviations.Deviations

/** A `coding-standards.xml` configuration file (usually generated from an YAML configuration file). */
class CodingStandardsFile extends XMLFile {
CodingStandardsFile() {
this.getBaseName() = "coding-standards.xml" and
// Must be within the users source code.
exists(this.getRelativePath())
}
}

class CodingStandardsConfigSection extends XMLElement {
CodingStandardsConfigSection() { getParent() instanceof CodingStandardsConfig }
}

/** A "Coding Standards" configuration file */
class CodingStandardsConfig extends XMLElement {
CodingStandardsConfig() {
any(CodingStandardsFile csf).getARootElement() = this and
this.getName() = "codingstandards"
}

/** Get a section in this configuration file. */
CodingStandardsConfigSection getASection() { result.getParent() = this }
}
26 changes: 19 additions & 7 deletions 26 cpp/common/src/codingstandards/cpp/Exclusions.qll
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,25 @@ predicate isExcluded(Element e) {
}

bindingset[e, query]
predicate isExcluded(Element e, Query query) {
e instanceof ExcludedElement
predicate isExcluded(Element e, Query query) { isExcluded(e, query, _) }

bindingset[e, query]
predicate isExcluded(Element e, Query query, string reason) {
e instanceof ExcludedElement and reason = "Element is an excluded element."
or
e.getFile() instanceof ExcludedFile
e.getFile() instanceof ExcludedFile and reason = "Element is part of an excluded file."
or
not exists(e.getFile())
not exists(e.getFile()) and reason = "Element is not part of the source repository."
or
// There exists a `DeviationRecord` that applies to this element and query
// There exists a `DeviationRecord` that applies to this element and query, and the query's effective category permits deviation.
query.getEffectiveCategory().permitsDeviation() and
exists(DeviationRecord dr | applyDeviationsAtQueryLevel() |
// The element is in a file which has a deviation for this query
exists(string path |
dr.isDeviated(query, path) and
e.getFile().getRelativePath().prefix(path.length()) = path
)
) and
reason = "Query has an associated deviation record for the element's file."
or
// The element is on the same line as a suppression comment
exists(Comment c |
Expand All @@ -50,6 +55,13 @@ predicate isExcluded(Element e, Query query) {
e.getLocation().hasLocationInfo(filepath, _, _, endLine, _) and
c.getLocation().hasLocationInfo(filepath, endLine, _, _, _)
)
)
) and
reason =
"Query has an associated deviation record with a code identifier that is applied to the element."
)
or
// The effective category of the query is 'Disapplied'.
// This can occur when a Guideline Recategorization Plan is applied.
query.getEffectiveCategory().isDisapplied() and
reason = "The query is disapplied."
}
42 changes: 12 additions & 30 deletions 42 cpp/common/src/codingstandards/cpp/deviations/Deviations.qll
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import cpp
import semmle.code.cpp.XML
import codingstandards.cpp.exclusions.RuleMetadata
import codingstandards.cpp.Config

predicate applyDeviationsAtQueryLevel() {
not exists(CodingStandardsReportDeviatedAlerts reportDeviatedResults |
Expand All @@ -15,26 +16,6 @@ predicate applyDeviationsAtQueryLevel() {
)
}

/** A `coding-standards.xml` configuration file (usually generated from an YAML configuration file). */
class CodingStandardsFile extends XMLFile {
CodingStandardsFile() {
this.getBaseName() = "coding-standards.xml" and
// Must be within the users source code.
exists(this.getRelativePath())
}
}

/** A "Coding Standards" configuration file */
class CodingStandardsConfig extends XMLElement {
CodingStandardsConfig() {
any(CodingStandardsFile csf).getARootElement() = this and
this.getName() = "codingstandards"
}

/** Gets a deviation record for this configuration. */
DeviationRecord getADeviationRecord() { result = getAChild().(DeviationRecords).getAChild() }
}

/** An element which tells the analysis whether to report deviated results. */
class CodingStandardsReportDeviatedAlerts extends XMLElement {
CodingStandardsReportDeviatedAlerts() {
Expand All @@ -44,19 +25,13 @@ class CodingStandardsReportDeviatedAlerts extends XMLElement {
}

/** A container of deviation records. */
class DeviationRecords extends XMLElement {
DeviationRecords() {
getParent() instanceof CodingStandardsConfig and
hasName("deviations")
}
class DeviationRecords extends CodingStandardsConfigSection {
DeviationRecords() { hasName("deviations") }
}

/** A container for the deviation permits records. */
class DeviationPermits extends XMLElement {
DeviationPermits() {
getParent() instanceof CodingStandardsConfig and
hasName("deviation-permits")
}
class DeviationPermits extends CodingStandardsConfigSection {
DeviationPermits() { hasName("deviation-permits") }
}

/** A deviation permit record, that is specified by a permit identifier */
Expand Down Expand Up @@ -357,6 +332,13 @@ class DeviationRecord extends XMLElement {
hasPermitId() and
not hasADeviationPermit() and
result = "There is no deviation permit with id `" + getPermitId() + "`."
or
exists(Query q | q.getQueryId() = getQueryId() |
not q.getEffectiveCategory().permitsDeviation() and
result =
"The deviation is applied to a query with the rule category '" +
q.getEffectiveCategory().toString() + "' that does not permit a deviation."
)
}

/** Holds if the deviation record is valid */
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.