Show HN: How to ensure JavaScript code quality
deepscan.io
deepscan.io
It is a bigger problem than I know how to fix. We even have a similar static analysis tool on our code, but when there are thousands and thousands of existing issues pointed out by it no one really cares about adding a few more to the pile.
I tried to promote typescript and rewriting over time. I can’t seem to get our front end developers to understand the value, or care. It’s totally my failure; it hurts my soul.
It’s honest to god something of an existential crisis for me.
I hunkered down in primarily backend over the nightmare that is our JS, whereas I spent nearly ten years full stack. Sigh.
I used eslint ( https://eslint.org ) and prettier ( https://prettier.io ), and using airbnb's JavaScript Style Guide as a reference point ( https://github.com/airbnb/javascript ), I would enable rules one by one. Then slowly rule by rule (commit by commit) I would clean up the code base.
We segmented by creating a legacy folder with the old standard and a folder for the new code that has strict linting rules.
If you created something new or did substantial changes to something existing it should go into the new folder. That way the code quality improvement became a natural part of our work process, and we did not have to touch parts just to improve code quality. For that serves quite little value by itself.
I would not want my linter to load multiple files, since that pattern of polluting the global namespace is really not maintainable.
The fix can be fairly simple if you wrap your entire b.js file in a function that takes an argument of 'hello' which you invoke from a.js.
If that doesn't work because you have too many global declarations you should probably just dump all the code into one giant file.
That might seem terrible and unmaintainable, but it is exactly what you already have.
Once the mess is all in one spot you can use a linter to start improving the quality, and begin breaking of the code into actual modules.
Sounds too scary.
I am facing the same problem of too many global declarations all thrown into a global soup during build time when all js files are concatenated.
I am looking for a safe and methodological method. By safe I mean a method that a robot can understand. If you leave room for thinking then people start making mistakes.
It's hard enough to get the green light for starting such project. If you start breaking stuff as well, you're going to burn the credit for refactor real quick
Except instead of modifying my config over time, I add a /* eslint ignore */ to the top of every existing file.
Every new file will be coded to the new standard, and as I open old files to tweak them I take the opportunity to clean them up.
Javascript is powerful and flexible, and sometimes that's a flaw.
It sounds like you need an architect who can look into modularization and setting some standards to in which teams are accountable. This isn't a perfect process, it usually takes a few iterations to see progress, and it requires a pitch to your business side of the house (usually along the lines of "Hey, we need more time to do maintenance work, but it'll drastically lower bugs seen by end users").
Programming is about trade offs, and typescript offers you a fixed set of tradeoffs - much more project complexity for type checking ahead of time. That can be valuable in some instances - when one codebase has to be shared across a lot of team members that are unable to communicate well. But typically the better fix is to break down and modularize code so that we smaller, more easily managed pieces that can be handled by just a few hands.
The JavaScript ecosystem is big because crappy developers are addicted to stupid. Impose hard lines in your office to ban unnecessary abstractions, large frameworks, offload extraneous build steps, and trim off as much as you can. Do this and don't allow stupid back in.
Is that going to scare the crap out of insecure developers. Absolutely. They can get over it (and you can train them) or they can go somewhere else. If you want small manageable code this is the hard choice you have to make.
If you are not willing to make hard decisions (and tell the cry babies to STFU) then don't complain about big code. This trauma is completely self-induced.
This doesn't seem to be a linter though, the copy says it will find actual bugs.
What about just making sure the pile doesn't grow bigger? Can you add something that warns you when your total percentage of erroneous/bad code goes up? This should help to prevent adding new bad code, and rewards refactoring old bad code.
Well, if your programmers don't care, there's nothing any tool can do about it.
Time for some people leadership. Get them motivated. Make them care.
If I were in the same situation, I would start looking elsewhere.
"For demo and editor plugins, we store the source content transmitted to the server as a temporary file. Right after the inspection, the file is completely deleted."
myFunction() {
for (var x in xs) { .. }
for (var x in xs2) { .. }
}
it would complain about "Duplicate declaration of variable 'x'". Understandable, but then I'd like to know the javascript context information (apparently x is not in a sub-scope (as in most languages), but in the main function scope).
2) GitHub integration would be nice. A button when looking at source in GitHub which annotates the code with warnings would be quite an improvement over the current view.1) We will consider adding explanation like "Note that 'x' is declared in function scope. Consider using 'let' declaration if you intended block scope".
2) Yes. Directly showing warnings in the GitHub site would be a nice feature. We will consider it in our roadmap.
For example, BAD_MIN_MAX_FUNC rule detects an error in the following code, which is beyond type checking.
x = Math.min(0, Math.max(100, x)); // BAD_MIN_MAX_FUNC alarm. The result is always 0.
The main diffrenece with JIRA ticket management is that it operates using information from code itself.For example, it automatically tracks fixed and newly detected issues by a feature called historical defect merging.
Pricing
We are in BETA stage and do not provide paid plans yet.
But open source projects are free and one private project is for your trial experience.
If you're interested in using DeepScan for more private projects, please contact us.
var lave = eval(atob(document.location.hash.slice(1)))
console.log(lave.name)One Advantage I can think of of running such analysis on GitHub would be automatically analyzing pull requests.
You can check out more detail in https://deepscan.io/docs/get-started/basics/#non-github
For comparison with Java, DeepScan is like FindBugs.
Check the reply that I have wrote for shamas.
In the meantime, you can try editor plugins if you are using Visual Studio Code or Atom.
Check https://deepscan.io/docs/get-started/basics/#non-github for details.
- Visual Studio Code: https://marketplace.visualstudio.com/items?itemName=DeepScan...