4 ms·
Ask HN: Looking for a tool
I'm not even sure what to type in Google.
Let's say I have a commit. I want a tool which analyzes codebase and show all places in code which could be affected by this commit. For example if I change a function X the tool will show all places which depends on a result of the function.
I guess that in Java it could be doable because of its strict nature. Is there anything like this? Or it's an idea for a side-project?
- BjoernKW 9y agoIt's called static analysis, which given JavaScript's dynamic nature obviously doesn't work as well as with statically-typed languages like Java. However, IntelliJ IDEA or WebStorm offer decent analysis tools for JavaScript as well. In IntelliJ IDEA "Find usages" is the name of the feature you're looking for.
- meric 9y agoIt's theoretically possible in JavaScript I think - you can trace the usage of the function return through variable assignment statements, insertions into arrays, etc. Not easy but not impossible?
- szatkus 9y agoI don't have IntelliJ right now, but as far as I remember this function shows only line where selected method is called. I meant something more sophisticated, every piece fo code that could be affected by this. Example: int x = obj.something(); unrelated.doSomethingElse(); return x * x; If I change something() method IntelliJ will show only the first line, even though the third one is affected by the change as well.
- BjoernKW 9y agoI see. Like a trace of properties affected by a change. That's definitely possible using static analysis during a pre-commit hook. You're right IntelliJ IDEA doesn't provide that feature out-of-the-box. SonarLint does something like this but only for specific patterns (or rather anti-patterns). I don't know about a general purpose tool that does this though.
- stephenr 9y agoWhat language is your project? Jetbrains IDEs have static analysis based "find usage" for dynamic languages like php.
- remyp 9y agoGood test coverage goes a long way towards solving this problem.
- rawland 9y agogrep -inr 'X' Can be expanded via regex, awk, etc...
- tehlike 9y agoNo. What if its a nested call?
- deleted 9y ago[deleted]
- paradite 9y agoYou can definitely write a tool to do it for JavaScript. Sublime text has something similar that gives you the usages of a function when you hover over its name. Its not as 100 percent accurate as strict static code analysis, but it works pretty well for function names that are not duplicated everywhere.
- gvisoc 9y agoThat particular sub-area of static analysis is called (change) impact analysis. If you google that you'll find several tools, but many of those results are a couple of years old, or framework-specific. Take a look and good luck.