Skip to content

Commit

Permalink
Merge pull request #12 from commentcov/ignore_nolint
Browse files Browse the repository at this point in the history
feat: ignore nolint comment as comment-coverage
  • Loading branch information
terakoya76 committed Jun 16, 2022
2 parents 2703dd0 + d85a7b4 commit 315705a
Show file tree
Hide file tree
Showing 4 changed files with 450 additions and 19 deletions.
33 changes: 16 additions & 17 deletions ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"go/parser"
"go/token"
"path/filepath"
"strings"

"github.com/commentcov/commentcov/proto"
"github.com/hashicorp/go-hclog"
Expand Down Expand Up @@ -80,9 +79,9 @@ func ProcessPackageCoverage(file string, fset *token.FileSet, f *ast.File) *prot
csp := fset.Position(cg.Pos())
cep := fset.Position(cg.End())

if IsHeader(fset, cg, block) {
if IsHeader(fset, cg, block) && !IsOnlyNoLintAnnotation(cg.Text()) {
d := &proto.Comment{
Comment: strings.TrimLeft(cg.Text(), " "),
Comment: Normalize(cg.Text()),
Block: &proto.Block{
StartLine: uint32(csp.Line),
StartColumn: uint32(csp.Column),
Expand All @@ -93,9 +92,9 @@ func ProcessPackageCoverage(file string, fset *token.FileSet, f *ast.File) *prot
hcs = append(hcs, d)
}

if IsInline(fset, cg, block) {
if IsInline(fset, cg, block) && !IsOnlyNoLintAnnotation(cg.Text()) {
d := &proto.Comment{
Comment: strings.TrimLeft(cg.Text(), " "),
Comment: Normalize(cg.Text()),
Block: &proto.Block{
StartLine: uint32(csp.Line),
StartColumn: uint32(csp.Column),
Expand Down Expand Up @@ -143,9 +142,9 @@ func ProcessFunctionCoverage(file string, fset *token.FileSet, f *ast.File, fdec
csp := fset.Position(cg.Pos())
cep := fset.Position(cg.End())

if IsHeader(fset, cg, block) {
if IsHeader(fset, cg, block) && !IsOnlyNoLintAnnotation(cg.Text()) {
d := &proto.Comment{
Comment: strings.TrimLeft(cg.Text(), " "),
Comment: Normalize(cg.Text()),
Block: &proto.Block{
StartLine: uint32(csp.Line),
StartColumn: uint32(csp.Column),
Expand All @@ -156,9 +155,9 @@ func ProcessFunctionCoverage(file string, fset *token.FileSet, f *ast.File, fdec
hcs = append(hcs, d)
}

if IsInline(fset, cg, block) {
if IsInline(fset, cg, block) && !IsOnlyNoLintAnnotation(cg.Text()) {
d := &proto.Comment{
Comment: strings.TrimLeft(cg.Text(), " "),
Comment: Normalize(cg.Text()),
Block: &proto.Block{
StartLine: uint32(csp.Line),
StartColumn: uint32(csp.Column),
Expand Down Expand Up @@ -212,9 +211,9 @@ func ProcessVariableCoverage(file string, fset *token.FileSet, f *ast.File, gdec
csp := fset.Position(cg.Pos())
cep := fset.Position(cg.End())

if IsHeader(fset, cg, block) {
if IsHeader(fset, cg, block) && !IsOnlyNoLintAnnotation(cg.Text()) {
d := &proto.Comment{
Comment: strings.TrimLeft(cg.Text(), " "),
Comment: Normalize(cg.Text()),
Block: &proto.Block{
StartLine: uint32(csp.Line),
StartColumn: uint32(csp.Column),
Expand All @@ -225,9 +224,9 @@ func ProcessVariableCoverage(file string, fset *token.FileSet, f *ast.File, gdec
hcs = append(hcs, d)
}

if IsInline(fset, cg, block) {
if IsInline(fset, cg, block) && !IsOnlyNoLintAnnotation(cg.Text()) {
d := &proto.Comment{
Comment: strings.TrimLeft(cg.Text(), " "),
Comment: Normalize(cg.Text()),
Block: &proto.Block{
StartLine: uint32(csp.Line),
StartColumn: uint32(csp.Column),
Expand Down Expand Up @@ -293,9 +292,9 @@ func ProcessTypeCoverage(file string, fset *token.FileSet, f *ast.File, gdecl *a
csp := fset.Position(cg.Pos())
cep := fset.Position(cg.End())

if IsHeader(fset, cg, block) {
if IsHeader(fset, cg, block) && !IsOnlyNoLintAnnotation(cg.Text()) {
d := &proto.Comment{
Comment: strings.TrimLeft(cg.Text(), " "),
Comment: Normalize(cg.Text()),
Block: &proto.Block{
StartLine: uint32(csp.Line),
StartColumn: uint32(csp.Column),
Expand All @@ -306,9 +305,9 @@ func ProcessTypeCoverage(file string, fset *token.FileSet, f *ast.File, gdecl *a
hcs = append(hcs, d)
}

if IsInline(fset, cg, block) {
if IsInline(fset, cg, block) && !IsOnlyNoLintAnnotation(cg.Text()) {
d := &proto.Comment{
Comment: strings.TrimLeft(cg.Text(), " "),
Comment: Normalize(cg.Text()),
Block: &proto.Block{
StartLine: uint32(csp.Line),
StartColumn: uint32(csp.Column),
Expand Down
Loading

0 comments on commit 315705a

Please sign in to comment.