Skip to content

Base check level on superproject type #113

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 1 commit into from
Dec 17, 2020
Merged
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
5 changes: 3 additions & 2 deletions check/checklevel/checklevel.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/arduino/arduino-lint/check/checkresult"
"github.com/arduino/arduino-lint/configuration"
"github.com/arduino/arduino-lint/configuration/checkmode"
"github.com/arduino/arduino-lint/project"
)

// Type is the type for the check levels.
Expand All @@ -38,11 +39,11 @@ const (
)

// CheckLevel determines the check level assigned to the given result of the given check under the current tool configuration.
func CheckLevel(checkConfiguration checkconfigurations.Type, checkResult checkresult.Type) (Type, error) {
func CheckLevel(checkConfiguration checkconfigurations.Type, checkResult checkresult.Type, checkedProject project.Type) (Type, error) {
if checkResult != checkresult.Fail {
return Notice, nil // Level provided by FailCheckLevel() is only relevant for failure result.
}
configurationCheckModes := configuration.CheckModes(checkConfiguration.ProjectType)
configurationCheckModes := configuration.CheckModes(checkedProject.SuperprojectType)
return FailCheckLevel(checkConfiguration, configurationCheckModes)
}

Expand Down
8 changes: 7 additions & 1 deletion check/checklevel/checklevel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"github.com/arduino/arduino-lint/check/checkresult"
"github.com/arduino/arduino-lint/configuration"
"github.com/arduino/arduino-lint/configuration/checkmode"
"github.com/arduino/arduino-lint/project"
"github.com/arduino/arduino-lint/project/projecttype"
"github.com/arduino/arduino-lint/util/test"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -63,7 +65,11 @@ func TestCheckLevel(t *testing.T) {
ErrorModes: testTable.errorModes,
}

level, err := CheckLevel(checkConfiguration, testTable.checkResult)
checkedProject := project.Type{
SuperprojectType: projecttype.Sketch,
}

level, err := CheckLevel(checkConfiguration, testTable.checkResult, checkedProject)
testTable.errorAssertion(t, err, testTable.testName)
if err == nil {
assert.Equal(t, testTable.expectedLevel, level, testTable.testName)
Expand Down
2 changes: 1 addition & 1 deletion result/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (results *Type) Initialize() {

// Record records the result of a check and returns a text summary for it.
func (results *Type) Record(checkedProject project.Type, checkConfiguration checkconfigurations.Type, checkResult checkresult.Type, checkOutput string) string {
checkLevel, err := checklevel.CheckLevel(checkConfiguration, checkResult)
checkLevel, err := checklevel.CheckLevel(checkConfiguration, checkResult, checkedProject)
if err != nil {
panic(fmt.Errorf("Error while determining check level: %v", err))
}
Expand Down
2 changes: 1 addition & 1 deletion result/result_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func TestRecord(t *testing.T) {
assert.Equal(t, checkConfiguration.Brief, checkReport.Brief)
assert.Equal(t, checkConfiguration.Description, checkReport.Description)
assert.Equal(t, checkResult.String(), checkReport.Result)
checkLevel, _ := checklevel.CheckLevel(checkConfiguration, checkResult)
checkLevel, _ := checklevel.CheckLevel(checkConfiguration, checkResult, checkedProject)
assert.Equal(t, checkLevel.String(), checkReport.Level)
assert.Equal(t, checkOutput, checkReport.Message)

Expand Down