Comments (9)
It's not very frequent to split packages like this in Go.
For example:
- there is no
expr
,stmt
anddecl
packages, onlyast
which includes all of them. - compiler optimizations are all part of
ssa
package, it defines multiple optimization passes just like we define multiple checkers inside one package.
There are no circular imports in Go, you can't import A
from B
if B
imports A
.
This means that code re-use can get complicated and require much architectural thinking to overcome it.
For example, lint.Warning
required by all checkers, so each checker package will import lint
.
But we also need lint.Warning
in user code (one of them is cmd/kfulint
, there can be more later).
So, we will get circular dependency.
Checker-related functionality is not "global", it only occupies checker method set.
All unexported functions that are global (util.go
) are global by design,
to be re-used between different checkers.
Also note that long package names in Go are also not idiomatic.
They're usually 3-8 chars long, and consist of 1 word (with exception of foo_test
idioms).
In C++ you would not move each checker to a separate namespace either, right?
Anyway, I'm voting for long consideration until this is done.
I agree that lint.NewXYZ
looks weird in linter main, but that can change in near future,
we don't figured out good alternative yet, and package.New
does not solve the problem, it only changes the names.
from go-critic.
When we spoken earlier about linter-specific directory split, I though about test files from testdata
.
from go-critic.
Oh, circular imports are pain.. Doesn't go have patterns to resolve them, like predefined structures?
In c++ i would have been put every "private function" in cpp file to hide them. Not now, but later huge amount of "visible" functions in packet can be a problem.
from go-critic.
Which functions do you refer to?
from go-critic.
In checker A I see all exported/unexported functions from checker B.
from go-critic.
But you shouldn't ever have an instance of other checker inside other checker in a first place.
Such code will never pass the review.
And if your autocomplete somehow gives you B
methods for A
type, that's editor problem, not architectural.
from go-critic.
Every abstraction and incapsulation is a convention for a degree.
In C++ you can include cpp
files, and you can do #define private public
; you can also do many things with unsafe tricks and assembler that break incapsulation (can "private" save from invalid pointer cast or arbitrary memory read?).
This doesn't automatically mean that all C++ code is bad, right? (Well, this is arguable...)
from go-critic.
Oh, my bad. I hadn't thought about it.
I rly forgot that every function in cheker refers to it's own type.
Sry for waisting your time.
from go-critic.
@fexolm, that's not a time wasting, it's a discussion. :)
You're welcome.
from go-critic.
Related Issues (20)
- Compilation error under Go 1.20 HOT 3
- Non zero exit code in case of issues
- Ignore generated files or specific directory? HOT 2
- New release? HOT 6
- How to speed it up HOT 18
- redundantSprint false positive with err.Error() when err is nil HOT 1
- new check: mismatching format HOT 1
- httpNoBody: also warn on using "nil" instead of "http.NoBody" on (net/http/httptest).NewRequest HOT 3
- go1.21: load rules: parse rules file: typechecker error: ...: could not import HOT 5
- sloppyTestFuncName incorrectly identifies helper function HOT 2
- new check: find identical condition
- bug: `rangeValCopy` still panics on code with generics HOT 3
- new check: I/O find close twice HOT 1
- go1.21: load embedded ruleguard rules: rules/rules.go:13: can't load fmt HOT 14
- unlambda: false positive HOT 1
- timeCmpSimplify: false positive, not before is unequal to after HOT 2
- dynamicFmtString: use rather fix errors.New than fmt.Errorf("%s" HOT 2
- new check: detect unnecessary gomock controller Finish call HOT 1
- `gocritic check` panics with invalid memory address or nil pointer dereference HOT 4
- emptyStringTest: handle len(s) > 0
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-critic.