5 ms·
I beg to differ, to me python (and js) are tolerable languages only when they are controlled with linters and automated tests. And pylint is still the best lint
by gbog 10y ago
I beg to differ, to me python (and js) are tolerable languages only when they are controlled with linters and automated tests. And pylint is still the best linter for big python projects. It is fully configurable and each and every default rule is interesting per se. For example, a class with no `__init__`, no or too many attributes or methods, is a potential code smell and candidate for refactoring.
- emidln 10y agoPylint complains about: foo = functools.partial(bar, 'baz') because it thinks foo is a global constant and thus should be upcased. It can DIAF.
- tclancy 10y agoThis is exactly why it has ignore flags. Remember Python's attitude is "explicit is better than implicit": if you know what you are doing, you just put a flag over it. pylint is trying to catch the cases where a person didn't know what they're doing. I'd rather have to add a flag than have it miss those.
- gbog 10y agoAre you not in the module's global scope? If you are pylint is right and you wrong, you need to move this line inside a function or a class. There should be no code running at module level. Here you might argue that this is akin to a decorator, and that bar will not be called, so yes it is a corner case, but the main rule (only allow consts at module level) is still useful, and I'd say vital even.
- emidln 10y agoThis is not 'akin to a decorator', it's is partial function! Do you name your functions: def THIS_IS_IN_GLOBAL_SCOPE(): ... Of course you don't! Then why would you consider forcing someone to write this: def bar(spam, eggs): print spam, eggs def foo(eggs): return bar('baz', eggs) Which even manages to lose information, hence why functools.partial exists in the first place. This is bad because readers now see FOO and think it's a constant: FOO = functools.partial(bar, 'baz')
- sly010 10y agoI don't know any other linter for any other language that complains about too many methods (or too many lines in a method, or too long variable names, etc) in a class. I should know my domain better than pylint.
- tclancy 10y agoIt's not specific to a language. Those are all code complexity measures. When you see those flags you should at least consider refactoring (and if things are best the way they are you can put a pylint-ignore comment with an explanation right above it).
- web007 10y agoPerl generates McCabe scores, and can arbitrarily limit on complexity. That's a better proxy than "number of lines", but tends to be equivalent.
- frobozz 10y agoPMD: http://pmd.sourceforge.net/snapshot/pmd-java/rules/java/codesize.html#ExcessivePublicCount http://pmd.sourceforge.net/snapshot/pmd-java/rules/java/code... Scalastyle: http://www.scalastyle.org/rules-0.8.0.html#org_scalastyle_scalariform_NumberOfMethodsInTypeChecker http://www.scalastyle.org/rules-0.8.0.html#org_scalastyle_sc... JSHint: http://jshint.com/docs/options/#maxstatements http://jshint.com/docs/options/#maxstatements