Repository: mgechev/revive (go)

Issue:
Linter rule to check the consistency of make(map[type]type) vs empty map[type]type{}
**Is your feature request related to a problem? Please describe.**
There are two ways of declaring a map: either via `make` or via literal. Some projects might want to require to be consistent by choosing this or that way of map declaration.

**Describe the solution you'd like**
I'd like to let the user choose between the styles (either `make` or via literal). `make(map[type]type, size)` will always be allowed, as well as `map[type]type{k1: v1, k2: v2}`. I'm also considering an option to check or ignore map descendant types (e.g. `type Map map[string]string`), on by default.

**Describe alternatives you've considered**
I didn't find any solution.

**Additional context**
IMO, consistent code, be it opinionated or not, is better than inconsistent. Also, I'm in favor for `make(map[type]type)` because it's then consistent with `make(map[type]type, size)`. Also, when a descendant type is declared and then used, it's not clear for the reader if it's a struct or a map, when we call it as `Map{}`.

P.S. I can implement such a linter rule, if it makes sense to the others.


Pull request description:
feat: add support for enforce-map-style rule 
closes #892

Patch:
diff --git a/README.md b/README.md
index daadbc1..cdcd202 100644
--- a/README.md
+++ b/README.md
@@ -464,6 +464,7 @@ List of all available rules. The rules ported from `golint` are left unchanged a
 | [`context-keys-type`](./RULES_DESCRIPTIONS.md#context-key-types)   |  n/a   | Disallows the usage of basic types in `context.WithValue`.       |   yes    |  yes  |
 | [`time-equal`](./RULES_DESCRIPTIONS.md#time-equal)         |  n/a   | Suggests to use `time.Time.Equal` instead of `==` and `!=` for equality check time.                 |   no    |  yes  |
 | [`time-naming`](./RULES_DESCRIPTIONS.md#time-naming)         |  n/a   | Conventions around the naming of time variables.                 |   yes    |  yes  |
+| [`unchecked-type-assertions`](./RULES_DESCRIPTIONS.md#unchecked-type-assertions)         |  n/a   | Disallows type assertions without checking the result.                 |   no    |  yes  |
 | [`var-declaration`](./RULES_DESCRIPTIONS.md#var-declaration)     |  n/a   | Reduces redundancies around variable declaration.                |   yes    |  yes  |
 | [`unexported-return`](./RULES_DESCRIPTIONS.md#unexported-return)   |  n/a   | Warns when a public return is from unexported type.              |   yes    |  yes  |
 | [`errorf`](./RULES_DESCRIPTIONS.md#errorf)              |  n/a   | Should replace `errors.New(fmt.Sprintf())` with `fmt.Errorf()`   |   yes    |  yes  |
@@ -534,6 +535,7 @@ List of all available rules. The rules ported from `golint` are left unchanged a
 | [`comment-spacings`](./RULES_DESCRIPTIONS.md#comment-spacings)          |  []string   |  Warns on malformed comments |    no    |  no   |
 | [`redundant-import-alias`](./RULES_DESCRIPTIONS.md#redundant-import-alias)          |  n/a   |  Warns on import aliases matching the imported package name |    no    |  no   |
 | [`import-alias-naming`](./RULES_DESCRIPTIONS.md#import-alias-naming)         | string (defaults to ^[a-z][a-z0-9]{0,}$) | Conventions around the naming of import aliases.                              |    no    |  no   |
+| [`enforce-map-style`](./RULES_DESCRIPTIONS.md#enforce-map-style) |  string (defaults to "any")  |  Enforces consistent usage of `make(map[type]type)` or `map[type]type{}` for map initialization. Does not affect `make(map[type]type, size)` constructions. |    no    |  no   |
 
 
 ## Configurable rules
diff --git a/RULES_DESCRIPTIONS.md b/RULES_DESCRIPTIONS.md
index 4561e20..d7b0b1f 100644
--- a/RULES_DESCRIPTIONS.md
+++ b/RULES_DESCRIPTIONS.md
@@ -62,6 +62,7 @@ List of all available rules.
   - [string-format](#string-format)
   - [superfluous-else](#superfluous-else)
   - [time-equal](#time-equal)
+  - [unchecked-type-assertion](#unchecked-type-assertion)
   - [time-naming](#time-naming)
   - [var-naming](#var-naming)
   - [var-declaration](#var-declaration)
@@ -170,8 +171,8 @@ Example:
 [rule.cognitive-complexity]
   arguments =[7]
 ```
-
 ## comment-spacings
+
 _Description_: Spots comments of the form:
 ```go
 //This is a malformed comment: no space between // and the start of the sentence
@@ -332,6 +333,22 @@ _Description_: Sometimes `gofmt` is not enough to enforce a common formatting of
 
 _Configuration_: N/A
 
+## enforce-map-style
+
+_Description_: This rule enforces consistent usage of `make(map[type]type)` or `map[type]type{}` for map initialization. It does not affect `make(map[type]type, size)` constructions as well as `map[type]type{k1: v1}`.
+
+_Configuration_: (string) Specifies the enforced style for map initialization. The options are:
+- "any": No enforcement (default).
+- "make": Enforces the usage of `make(map[type]type)`.
+- "literal": Enforces the usage of `map[type]type{}`.
+
+Example:
+
+```toml
+[rule.enforce-map-style]
+  arguments = ["make"]
+```
+
 ## error-naming
 
 _Description_: By convention, for the sake of readability, variables of type `error` must be named with the prefix `err`.
@@ -683,6 +700,26 @@ _Description_: Using unit-specific suffix like "Secs", "Mins", ... when naming v
 
 _Configuration_: N/A
 
+## unchecked-type-assertion
+
+_Description_: This rule checks whether a type assertion result is checked (the `ok` value), preventing unexpected `panic`s.
+
+_Configuration_: list of key-value-pair-map (`[]map[string]any`).
+
+- `acceptIgnoredAssertionResult` : (bool) default `false`, set it to `true` to accept ignored type assertion results like this:
+
+```go
+foo, _ := bar(.*Baz).
+//   ^
+```
+
+Example:
+
+```yaml
+[rule.unchecked-type-assertion]
+arguments = [{acceptIgnoredAssertionResult=true}]
+```
+
 ## var-naming
 
 _Description_: This rule warns when [initialism](https://github.com/golang/go/wiki/CodeReviewComments#initialisms), [variable](https://github.com/golang/go/wiki/CodeReviewComments#variable-names) or [package](https://github.com/golang/go/wiki/CodeReviewComments#package-names) naming conventions are not followed.
diff --git a/config/config.go b/config/config.go
index 4385459..abd554a 100644
--- a/config/config.go
+++ b/config/config.go
@@ -80,6 +80,7 @@ var allRules = append([]lint.Rule{
 	&rule.FunctionLength{},
 	&rule.NestedStructs{},
 	&rule.UselessBreak{},
+	&rule.UncheckedTypeAssertionRule{},
 	&rule.TimeEqualRule{},
 	&rule.BannedCharsRule{},
 	&rule.OptimizeOperandsOrderRule{},
@@ -89,6 +90,7 @@ var allRules = append([]lint.Rule{
 	&rule.IfReturnRule{},
 	&rule.RedundantImportAlias{},
 	&rule.ImportAliasNamingRule{},
+	&rule.EnforceMapStyleRule{},
 }, defaultRules...)
 
 var allFormatters = []lint.Formatter{
diff --git a/go.sum b/go.sum
index d0f7028..29b30db 100644
--- a/go.sum
+++ b/go.sum
@@ -1,7 +1,5 @@
 github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8=
 github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
-github.com/chavacava/garif v0.0.0-20230608123814-4bd63c2919ab h1:5JxePczlyGAtj6R1MUEFZ/UFud6FfsOejq7xLC2ZIb0=
-github.com/chavacava/garif v0.0.0-20230608123814-4bd63c2919ab/go.mod h1:XMyYCkEL58DF0oyW4qDjjnPWONs2HBqYKI+UIPD+Gww=
 github.com/chavacava/garif v0.1.0 h1:2JHa3hbYf5D9dsgseMKAmc/MZ109otzgNFk5s87H9Pc=
 github.com/chavacava/garif v0.1.0/go.mod h1:XMyYCkEL58DF0oyW4qDjjnPWONs2HBqYKI+UIPD+Gww=
 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
diff --git a/rule/enforce-map-style.go b/rule/enforce-map-style.go
new file mode 100644
index 0000000..ae27b65
--- /dev/null
+++ b/rule/enforce-map-style.go
@@ -0,0 +1,164 @@
+package rule
+
+import (
+	"fmt"
+	"go/ast"
+	"sync"
+
+	"github.com/mgechev/revive/lint"
+)
+
+type enforceMapStyleType string
+
+const (
+	enforceMapStyleTypeAny     enforceMapStyleType = "any"
+	enforceMapStyleTypeMake    enforceMapStyleType = "make"
+	enforceMapStyleTypeLiteral enforceMapStyleType = "literal"
+)
+
+func mapStyleFromString(s string) (enforceMapStyleType, error) {
+	switch s {
+	case string(enforceMapStyleTypeAny), "":
+		return enforceMapStyleTypeAny, nil
+	case string(enforceMapStyleTypeMake):
+		return enforceMapStyleTypeMake, nil
+	case string(enforceMapStyleTypeLiteral):
+		return enforceMapStyleTypeLiteral, nil
+	default:
+		return enforceMapStyleTypeAny, fmt.Errorf(
+			"invalid map style: %s (expecting one of %v)",
+			s,
+			[]enforceMapStyleType{
+				enforceMapStyleTypeAny,
+				enforceMapStyleTypeMake,
+				enforceMapStyleTypeLiteral,
+			},
+		)
+	}
+}
+
+// EnforceMapStyleRule implements a rule to enforce `make(map[type]type)` over `map[type]type{}`.
+type EnforceMapStyleRule struct {
+	configured      bool
+	enforceMapStyle enforceMapStyleType
+	sync.Mutex
+}
+
+func (r *EnforceMapStyleRule) configure(arguments lint.Arguments) {
+	r.Lock()
+	defer r.Unlock()
+	
+	if r.configured {
+		return
+	}
+	r.configured = true
+
+	if len(arguments) < 1 {
+		r.enforceMapStyle = enforceMapStyleTypeAny
+		return
+	}
+
+	enforceMapStyle, ok := arguments[0].(string) 
+	if !ok {
+		panic(fmt.Sprintf("Invalid argument '%v' for 'enforce-map-style' rule. Expecting string, got %T", arguments[0], arguments[0]))
+	}
+
+	var err error
+	r.enforceMapStyle, err = mapStyleFromString(enforceMapStyle)
+
+	if err != nil {
+		panic(fmt.Sprintf("Invalid argument to the enforce-map-style rule: %v", err))
+	}
+}
+
+// Apply applies the rule to given file.
+func (r *EnforceMapStyleRule) Apply(file *lint.File, arguments lint.Arguments) []lint.Failure {
+	r.configure(arguments)
+
+	if r.enforceMapStyle == enforceMapStyleTypeAny {
+		// this linter is not configured
+		return nil
+	}
+
+	var failures []lint.Failure
+
+	astFile := file.AST
+	ast.Inspect(astFile, func(n ast.Node) bool {
+		switch v := n.(type) {
+		case *ast.CompositeLit:
+			if r.enforceMapStyle != enforceMapStyleTypeMake {
+				return true
+			}
+
+			if !r.isMapType(v.Type) {
+				return true
+			}
+
+			if len(v.Elts) > 0 {
+				// not an empty map
+				return true
+			}
+
+			failures = append(failures, lint.Failure{
+				Confidence: 1,
+				Node:       v,
+				Category:   "style",
+				Failure:    "use make(map[type]type) instead of map[type]type{}",
+			})
+		case *ast.CallExpr:
+			if r.enforceMapStyle != enforceMapStyleTypeLiteral {
+				// skip any function calls, even if it's make(map[type]type)
+				// we don't want to report it if literals are not enforced
+				return true
+			}
+
+			ident, ok := v.Fun.(*ast.Ident)
+			if !ok || ident.Name != "make" {
+				return true
+			}
+
+			if len(v.Args) != 1 {
+				// skip make(map[type]type, size) and invalid empty declarations
+				return true
+			}
+
+			if !r.isMapType(v.Args[0]) {
+				// not a map type
+				return true
+			}
+
+			failures = append(failures, lint.Failure{
+				Confidence: 1,
+				Node:       v.Args[0],
+				Category:   "style",
+				Failure:    "use map[type]type{} instead of make(map[type]type)",
+			})
+		}
+		return true
+	})
+
+	return failures
+}
+
+// Name returns the rule name.
+func (r *EnforceMapStyleRule) Name() string {
+	return "enforce-map-style"
+}
+
+func (r *EnforceMapStyleRule) isMapType(v ast.Expr) bool {
+	switch t := v.(type) {
+	case *ast.MapType:
+		return true
+	case *ast.Ident:
+		if t.Obj == nil {
+			return false
+		}
+		typeSpec, ok := t.Obj.Decl.(*ast.TypeSpec)
+		if !ok {
+			return false
+		}
+		return r.isMapType(typeSpec.Type)
+	default:
+		return false
+	}
+}
diff --git a/rule/unchecked-type-assertion.go b/rule/unchecked-type-assertion.go
new file mode 100644
index 0000000..df27743
--- /dev/null
+++ b/rule/unchecked-type-assertion.go
@@ -0,0 +1,194 @@
+package rule
+
+import (
+	"fmt"
+	"go/ast"
+	"sync"
+
+	"github.com/mgechev/revive/lint"
+)
+
+const (
+	ruleUTAMessagePanic   = "type assertion will panic if not matched"
+	ruleUTAMessageIgnored = "type assertion result ignored"
+)
+
+// UncheckedTypeAssertionRule lints missing or ignored `ok`-value in danymic type casts.
+type UncheckedTypeAssertionRule struct {
+	sync.Mutex
+	acceptIgnoredAssertionResult bool
+	configured                   bool
+}
+
+func (u *UncheckedTypeAssertionRule) configure(arguments lint.Arguments) {
+	u.Lock()
+	defer u.Unlock()
+
+	if len(arguments) == 0 || u.configured {
+		return
+	}
+
+	u.configured = true
+
+	args, ok := arguments[0].(map[string]any)
+	if !ok {
+		panic("Unable to get arguments. Expected object of key-value-pairs.")
+	}
+
+	for k, v := range args {
+		switch k {
+		case "acceptIgnoredAssertionResult":
+			u.acceptIgnoredAssertionResult, ok = v.(bool)
+			if !ok {
+				panic(fmt.Sprintf("Unable to parse argument '%s'. Expected boolean.", k))
+			}
+		default:
+			panic(fmt.Sprintf("Unknown argument: %s", k))
+		}
+	}
+}
+
+// Apply applies the rule to given file.
+func (u *UncheckedTypeAssertionRule) Apply(file *lint.File, args lint.Arguments) []lint.Failure {
+	u.configure(args)
+
+	var failures []lint.Failure
+
+	walker := &lintUnchekedTypeAssertion{
+		onFailure: func(failure lint.Failure) {
+			failures = append(failures, failure)
+		},
+		acceptIgnoredTypeAssertionResult: u.acceptIgnoredAssertionResult,
+	}
+
+	ast.Walk(walker, file.AST)
+
+	return failures
+}
+
+// Name returns the rule name.
+func (*UncheckedTypeAssertionRule) Name() string {
+	return "unchecked-type-assertion"
+}
+
+type lintUnchekedTypeAssertion struct {
+	onFailure                        func(lint.Failure)
+	acceptIgnoredTypeAssertionResult bool
+}
+
+func isIgnored(e ast.Expr) bool {
+	ident, ok := e.(*ast.Ident)
+	if !ok {
+		return false
+	}
+
+	return ident.Name == "_"
+}
+
+func isTypeSwitch(e *ast.TypeAssertExpr) bool {
+	return e.Type == nil
+}
+
+func (w *lintUnchekedTypeAssertion) requireNoTypeAssert(expr ast.Expr) {
+	e, ok := expr.(*ast.TypeAssertExpr)
+	if ok && !isTypeSwitch(e) {
+		w.addFailure(e, ruleUTAMessagePanic)
+	}
+}
+
+func (w *lintUnchekedTypeAssertion) handleIfStmt(n *ast.IfStmt) {
+	ifCondition, ok := n.Cond.(*ast.BinaryExpr)
+	if ok {
+		w.requireNoTypeAssert(ifCondition.X)
+		w.requireNoTypeAssert(ifCondition.Y)
+	}
+}
+
+func (w *lintUnchekedTypeAssertion) requireBinaryExpressionWithoutTypeAssertion(expr ast.Expr) {
+	binaryExpr, ok := expr.(*ast.BinaryExpr)
+	if ok {
+		w.requireNoTypeAssert(binaryExpr.X)
+		w.requireNoTypeAssert(binaryExpr.Y)
+	}
+}
+
+func (w *lintUnchekedTypeAssertion) handleCaseClause(n *ast.CaseClause) {
+	for _, expr := range n.List {
+		w.requireNoTypeAssert(expr)
+		w.requireBinaryExpressionWithoutTypeAssertion(expr)
+	}
+}
+
+func (w *lintUnchekedTypeAssertion) handleSwitch(n *ast.SwitchStmt) {
+	w.requireNoTypeAssert(n.Tag)
+	w.requireBinaryExpressionWithoutTypeAssertion(n.Tag)
+}
+
+func (w *lintUnchekedTypeAssertion) handleAssignment(n *ast.AssignStmt) {
+	if len(n.Rhs) == 0 {
+		return
+	}
+
+	e, ok := n.Rhs[0].(*ast.TypeAssertExpr)
+	if !ok || e == nil {
+		return
+	}
+
+	if isTypeSwitch(e) {
+		return
+	}
+
+	if len(n.Lhs) == 1 {
+		w.addFailure(e, ruleUTAMessagePanic)
+	}
+
+	if !w.acceptIgnoredTypeAssertionResult && len(n.Lhs) == 2 && isIgnored(n.Lhs[1]) {
+		w.addFailure(e, ruleUTAMessageIgnored)
+	}
+}
+
+// handles "return foo(.*bar)" - one of them is enough to fail as golang does not forward the type cast tuples in return statements
+func (w *lintUnchekedTypeAssertion) handleReturn(n *ast.ReturnStmt) {
+	for _, r := range n.Results {
+		w.requireNoTypeAssert(r)
+	}
+}
+
+func (w *lintUnchekedTypeAssertion) handleRange(n *ast.RangeStmt) {
+	w.requireNoTypeAssert(n.X)
+}
+
+func (w *lintUnchekedTypeAssertion) handleChannelSend(n *ast.SendStmt) {
+	w.requireNoTypeAssert(n.Value)
+}
+
+func (w *lintUnchekedTypeAssertion) Visit(node ast.Node) ast.Visitor {
+	switch n := node.(type) {
+	case *ast.RangeStmt:
+		w.handleRange(n)
+	case *ast.SwitchStmt:
+		w.handleSwitch(n)
+	case *ast.ReturnStmt:
+		w.handleReturn(n)
+	case *ast.AssignStmt:
+		w.handleAssignment(n)
+	case *ast.IfStmt:
+		w.handleIfStmt(n)
+	case *ast.CaseClause:
+		w.handleCaseClause(n)
+	case *ast.SendStmt:
+		w.handleChannelSend(n)
+	}
+
+	return w
+}
+
+func (w *lintUnchekedTypeAssertion) addFailure(n *ast.TypeAssertExpr, why string) {
+	s := fmt.Sprintf("type cast result is unchecked in %v - %s", gofmt(n), why)
+	w.onFailure(lint.Failure{
+		Category:   "bad practice",
+		Confidence: 1,
+		Node:       n,
+		Failure:    s,
+	})
+}


Test patch:
diff --git a/test/enforce-map-style_test.go b/test/enforce-map-style_test.go
new file mode 100644
index 0000000..21013bb
--- /dev/null
+++ b/test/enforce-map-style_test.go
@@ -0,0 +1,24 @@
+package test
+
+import (
+	"testing"
+
+	"github.com/mgechev/revive/lint"
+	"github.com/mgechev/revive/rule"
+)
+
+func TestEnforceMapStyle_any(t *testing.T) {
+	testRule(t, "enforce-map-style-any", &rule.EnforceMapStyleRule{})
+}
+
+func TestEnforceMapStyle_make(t *testing.T) {
+	testRule(t, "enforce-map-style-make", &rule.EnforceMapStyleRule{}, &lint.RuleConfig{
+		Arguments: []interface{}{"make"},
+	})
+}
+
+func TestEnforceMapStyle_literal(t *testing.T) {
+	testRule(t, "enforce-map-style-literal", &rule.EnforceMapStyleRule{}, &lint.RuleConfig{
+		Arguments: []interface{}{"literal"},
+	})
+}
diff --git a/test/unchecked_type_assertion_test.go b/test/unchecked_type_assertion_test.go
new file mode 100644
index 0000000..454923c
--- /dev/null
+++ b/test/unchecked_type_assertion_test.go
@@ -0,0 +1,20 @@
+package test
+
+import (
+	"testing"
+
+	"github.com/mgechev/revive/lint"
+	"github.com/mgechev/revive/rule"
+)
+
+func TestUncheckedDynamicCast(t *testing.T) {
+	testRule(t, "unchecked-type-assertion", &rule.UncheckedTypeAssertionRule{})
+}
+
+func TestUncheckedDynamicCastWithAcceptIgnored(t *testing.T) {
+	args := []any{map[string]any{
+		"acceptIgnoredAssertionResult": true,
+	}}
+
+	testRule(t, "unchecked-type-assertion-accept-ignored", &rule.UncheckedTypeAssertionRule{}, &lint.RuleConfig{Arguments: args})
+}
diff --git a/testdata/enforce-map-style-any.go b/testdata/enforce-map-style-any.go
new file mode 100644
index 0000000..3eec123
--- /dev/null
+++ b/testdata/enforce-map-style-any.go
@@ -0,0 +1,13 @@
+package fixtures
+
+func somefn() {
+	m1 := make(map[string]string)
+	m2 := map[string]string{}
+	m3 := make(map[string]string, 10)
+	m4 := map[string]string{"k1": "v1"}
+
+	_ = m1
+	_ = m2
+	_ = m3
+	_ = m4
+}
diff --git a/testdata/enforce-map-style-literal.go b/testdata/enforce-map-style-literal.go
new file mode 100644
index 0000000..a64d2e4
--- /dev/null
+++ b/testdata/enforce-map-style-literal.go
@@ -0,0 +1,51 @@
+package fixtures
+
+func somefn() {
+	m0 := make(map[string]string, 10)
+	m1 := make(map[string]string) // MATCH /use map[type]type{} instead of make(map[type]type)/
+	m2 := map[string]string{}
+	m3 := map[string]string{"k1": "v1", "k2": "v2"}
+
+	_ = m0
+	_ = m1
+	_ = m2
+	_ = m3
+}
+
+type Map map[string]string
+
+func somefn2() {
+	m0 := make(Map, 10)
+	m1 := make(Map) // MATCH /use map[type]type{} instead of make(map[type]type)/
+	m2 := Map{}
+	m3 := Map{"k1": "v1", "k2": "v2"}
+
+	_ = m0
+	_ = m1
+	_ = m2
+	_ = m3
+}
+
+type MapMap Map
+
+func somefn3() {
+	m0 := make(MapMap, 10)
+	m1 := make(MapMap) // MATCH /use map[type]type{} instead of make(map[type]type)/
+	m2 := MapMap{}
+	m3 := MapMap{"k1": "v1", "k2": "v2"}
+
+	_ = m0
+	_ = m1
+	_ = m2
+	_ = m3
+}
+
+func somefn4() {
+	m1 := map[string]map[string]string{}
+	m1["el0"] = make(map[string]string, 10)
+	m1["el1"] = make(map[string]string) // MATCH /use map[type]type{} instead of make(map[type]type)/
+	m1["el2"] = map[string]string{}
+	m1["el3"] = map[string]string{"k1": "v1", "k2": "v2"}
+
+	_ = m1
+}
diff --git a/testdata/enforce-map-style-make.go b/testdata/enforce-map-style-make.go
new file mode 100644
index 0000000..e990dce
--- /dev/null
+++ b/testdata/enforce-map-style-make.go
@@ -0,0 +1,51 @@
+package fixtures
+
+func somefn() {
+	m0 := make(map[string]string, 10)
+	m1 := make(map[string]string)
+	m2 := map[string]string{} // MATCH /use make(map[type]type) instead of map[type]type{}/
+	m3 := map[string]string{"k1": "v1", "k2": "v2"}
+
+	_ = m0
+	_ = m1
+	_ = m2
+	_ = m3
+}
+
+type Map map[string]string
+
+func somefn2() {
+	m0 := make(Map, 10)
+	m1 := make(Map)
+	m2 := Map{} // MATCH /use make(map[type]type) instead of map[type]type{}/
+	m3 := Map{"k1": "v1", "k2": "v2"}
+
+	_ = m0
+	_ = m1
+	_ = m2
+	_ = m3
+}
+
+type MapMap Map
+
+func somefn3() {
+	m0 := make(MapMap, 10)
+	m1 := make(MapMap)
+	m2 := MapMap{} // MATCH /use make(map[type]type) instead of map[type]type{}/
+	m3 := MapMap{"k1": "v1", "k2": "v2"}
+
+	_ = m0
+	_ = m1
+	_ = m2
+	_ = m3
+}
+
+func somefn4() {
+	m1 := map[string]map[string]string{} // MATCH /use make(map[type]type) instead of map[type]type{}/
+	m1["el0"] = make(map[string]string, 10)
+	m1["el1"] = make(map[string]string)
+	m1["el2"] = map[string]string{} // MATCH /use make(map[type]type) instead of map[type]type{}/
+	m1["el3"] = map[string]string{"k1": "v1", "k2": "v2"}
+
+	_ = m1
+}
diff --git a/testdata/unchecked-type-assertion-accept-ignored.go b/testdata/unchecked-type-assertion-accept-ignored.go
new file mode 100644
index 0000000..be38c83
--- /dev/null
+++ b/testdata/unchecked-type-assertion-accept-ignored.go
@@ -0,0 +1,12 @@
+package fixtures
+
+var foo any = "foo"
+
+func handleIgnoredIsOKByConfig() {
+	// No lint here bacuse `acceptIgnoredAssertionResult` is set to `true`
+	r, _ := foo.(int)
+}
+
+func handleSkippedStillFails() {
+	r := foo.(int) // MATCH /type cast result is unchecked in foo.(int) - type assertion will panic if not matched/
+}
diff --git a/testdata/unchecked-type-assertion.go b/testdata/unchecked-type-assertion.go
new file mode 100644
index 0000000..184008c
--- /dev/null
+++ b/testdata/unchecked-type-assertion.go
@@ -0,0 +1,108 @@
+package fixtures
+
+import "fmt"
+
+var (
+	foo  any = "foo"
+	bars     = []any{1, 42, "some", "thing"}
+)
+
+func handleIgnored() {
+	r, _ := foo.(int) // MATCH /type cast result is unchecked in foo.(int) - type assertion result ignored/
+}
+
+func handleSkipped() {
+	r := foo.(int) // MATCH /type cast result is unchecked in foo.(int) - type assertion will panic if not matched/
+}
+
+func handleReturn() int {
+	return foo.(int) // MATCH /type cast result is unchecked in foo.(int) - type assertion will panic if not matched/
+}
+
+func handleSwitch() {
+	switch foo.(int) { // MATCH /type cast result is unchecked in foo.(int) - type assertion will panic if not matched/
+	case 0:
+	case 1:
+		//
+	}
+}
+
+func handleRange() {
+	var some any = bars
+	for _, x := range some.([]string) { // MATCH /type cast result is unchecked in some.([]string) - type assertion will panic if not matched/
+		fmt.Println(x)
+	}
+}
+
+func handleTypeSwitch() {
+	// Should not be a lint
+	switch foo.(type) {
+	case string:
+	case int:
+		//
+	}
+}
+
+func handleTypeSwitchWithAssignment() {
+	// Should not be a lint
+	switch n := foo.(type) {
+	case string:
+	case int:
+		//
+	}
+}
+
+func handleTypeComparison() {
+	if foo.(int) == 1 { // MATCH /type cast result is unchecked in foo.(int) - type assertion will panic if not matched/
+		return
+	}
+}
+
+func handleTypeComparisonReverse() {
+	if 1 == foo.(int) { // MATCH /type cast result is unchecked in foo.(int) - type assertion will panic if not matched/
+		return
+	}
+}
+
+func handleTypeAssignmentComparison() {
+	var value any
+	value = 42 // int
+
+	if v := value.(int); v == 42 { // MATCH /type cast result is unchecked in value.(int) - type assertion will panic if not matched/
+		fmt.Printf("Value is an integer: %d\n", v)
+	}
+}
+
+func handleSwitchComparison() {
+	switch foo.(int) == 1 { // MATCH /type cast result is unchecked in foo.(int) - type assertion will panic if not matched/
+	case true:
+	case false:
+	}
+}
+
+func handleSwitchComparisonReverse() {
+	switch 1 == foo.(int) { // MATCH /type cast result is unchecked in foo.(int) - type assertion will panic if not matched/
+	case true:
+	case false:
+	}
+}
+
+func handleInnerSwitchAssertion() {
+	switch {
+	case foo.(int) == 1: // MATCH /type cast result is unchecked in foo.(int) - type assertion will panic if not matched/
+	case bar.(int) == 1: // MATCH /type cast result is unchecked in bar.(int) - type assertion will panic if not matched/
+	}
+}
+
+func handleInnerSwitchAssertionReverse() {
+	switch {
+	case 1 == foo.(int): // MATCH /type cast result is unchecked in foo.(int) - type assertion will panic if not matched/
+	case 1 == bar.(int): // MATCH /type cast result is unchecked in bar.(int) - type assertion will panic if not matched/
+	}
+}
+
+func handleChannelWrite() {
+	c := make(chan any)
+	var a any = "foo"
+	c <- a.(int) // MATCH /type cast result is unchecked in a.(int) - type assertion will panic if not matched/
+}