Repository navigation
feat: treat inequality comparisons as magic-string decision points - #215
Merged
Merged
Conversation
The `import` keyword was compared twice as a bare string while splitting a from-import into module and names. Name it once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A string repeated as an inequality operand (`!=`, `!==`, F#'s `<>`,
Erlang's `/=` and `=/=`) now counts toward the magic-string threshold,
including Rust's `kind != Some("x")`.
EqualityComparison gains a Polarity (Equal | NotEqual) so each adapter
still reads comparison operators in one place. TypeScript, Kotlin, C#,
and C++ share a new binaryComparisons helper in place of four copies of
the same operand/operator/operand extraction.
Match opportunities and stringly-typed control flow keep only Equal: an
inequality excludes one value rather than selecting a branch or a
state, so their findings are unchanged. Matrix rows cover the flagged
magic string and both clean scenarios in every language.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Energy State Diff vs
|
| File | Base | Head | Δ | Status |
|---|---|---|---|---|
| src/Core/Detectors/MatchOpportunitySupport.fs | 0 | 0 | 0 | ⚪ unchanged |
| src/Core/Detectors/PrimitiveObsession.fs | 4 | 4 | 0 | ⚪ unchanged |
| src/Core/LanguageAdapter.fs | 0 | 0 | 0 | ⚪ unchanged |
| src/Core/PythonTypeInfo/Imports.fs | 1 | 0 | -1 | 🟢 improved |
| src/Languages/CPlusPlus.fs | 0 | 0 | 0 | ⚪ unchanged |
| src/Languages/CSharp.fs | 0 | 0 | 0 | ⚪ unchanged |
| src/Languages/Erlang.fs | 0 | 0 | 0 | ⚪ unchanged |
| src/Languages/FSharp.fs | 0 | 0 | 0 | ⚪ unchanged |
| src/Languages/Kotlin.fs | 0 | 0 | 0 | ⚪ unchanged |
| src/Languages/Python.fs | 0 | 0 | 0 | ⚪ unchanged |
| src/Languages/Rust.fs | 0 | 0 | 0 | ⚪ unchanged |
| src/Languages/TypeScript.fs | 0 | 0 | 0 | ⚪ unchanged |
| tests/DetectorFixtureMatrixTests.fs | 4 | 4 | 0 | ⚪ unchanged |
13 files changed, 0 worsened, 1 improved, 0 new.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Last follow-up from #212. A string repeated as an inequality operand now counts toward the magic-string threshold, just like
==. This covers!=,!==, F#'s<>, and Erlang's/=and=/=, including Rust'skind != Some("x"). A typo instatus != "archived"silently flips a condition exactly as one in==does.Design
EqualityComparisongains aPolarity: ComparisonPolarity(Equal | NotEqual), so each adapter still reads comparison operators in one place:binaryComparisonswith a per-languageComparisonOperatorsrecord.comparison_operator), F# (infix_opwithconstunwrapping), Erlang (lhs/rhsfields) and Rust (operatorfield, with theSome("x")unwrapping) keep their shapes and learn the inequality operator.Other detectors are unchanged. Match opportunities and stringly-typed control flow (primitive obsession) keep only
Equal. An inequality excludes one value rather than selecting a branch or one of a variable's states. Both filters have ADCdecision:comments, and both detector docs state this.Separate commit
The new rule found the
importkeyword compared twice with<>inPythonTypeInfo/Imports.fs. It's now a named constant, andjust analyzereports the same findings asmain.Test plan
just test: 628 passed. New matrix scenarios:flaggedInequalityin Python, TypeScript/TSX, F#, Kotlin, C++ and C#, plusflagged_inequalityin Erlang and Rust.cleanInequalityChainin every language, an!=if/else chain that must not suggest a match.cleanInequalityChecks/clean_inequality, one variable!=three distinct strings, which must not count as stringly typed.Equalfilters fails 15 tests, one per language per detector. This confirms every adapter emitsNotEqualand the filters are what keep those detectors unchanged.just lint,just md-lintjust analyze: no new findings compared withmainkey != "notify"next to a("notify", …)pattern,!= "---"next to== "---", and so on)🤖 Generated with Claude Code