Comments (5)
This feature is really essential. Without it I just have to disable the whole linter, because 1
is often used in cycles.
from go-mnd.
@vitalyisaev2
I'll release it today. :) But can you please provide an example for the case you mentioned? Maybe I can exclude it by default.
from go-mnd.
@bishtawi
It's implemented. Please checkout the new version v1.2.0 :)
from go-mnd.
Hi @bishtawi,
currently that's not possible. But that would be a nice addition. I'll implement it soon.
from go-mnd.
@tommy-muehle thanks for the quick implementation of this feature!
Regarding to the cases where 1
should not be considered as a magic number, please have a look at these snippets.
Custom for
loop:
// custom for loop
for i, itemID := range ring {
next := i + 1
start := int(itemID)%ring.totalItems - 1
if start < 0 {
start += step
}
// ...
Branching based on int
value evaluation:
func computeResult(value int) ([][]int, error) {
if subsets == 0 {
return nil, fmt.Errorf("invalid value: 0")
}
if subsets == 1 {
return [][]int{{255}}, nil
}
// more complicated logic for other cases
To be honest, I have no idea which name should I use for a variable or constant that will be equal to 1
in order to make it non-magic number :)
from go-mnd.
Related Issues (20)
- need a way to ignore numbers in certain functions HOT 3
- Operations inside return statements are not being detected. HOT 2
- Multiplicative 2 should not be considered a magic number
- Constants typecasted trigger magic number. HOT 2
- time duration not considered a magic number HOT 4
- Go modules v2 compatibility HOT 1
- Floating point one `1.0` should not be considered as magic number HOT 2
- Concurrent map read and map write
- The results seem to be random HOT 4
- Literals in type conversions in block declarations should be okay HOT 2
- add ignored files will ignore all files HOT 2
- Magic number in second function parameter not reported HOT 2
- Duplicated code HOT 1
- `strconv.FormatInt` or `strconv.FormatUint` and magic numbers ? HOT 9
- Go built-in functions are not recognized when excluding functions
- Fails to detect magic number when initialized as part of "if"
- Does not work with go 1.20+
- Multiplicating two numbers and a duration is not reported HOT 1
- Feature request: Nolint rule for special cases, e.g. base 2 numbers
- How are we supposed to ignore "chained" function calls using regex?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-mnd.