Comments (7)
I have updated the issue description!
from checkstyle.
Hi @romani, yes, this is possible, but the picocli library does not offer special support for this.
This is up to the application to handle.
Basically, when the end user specifies -
as a file name, the application should not open a FileInputStream
from the specified path, but instead should start reading from STDIN, until EOF is reached.
Looking at the CheckStyle code,
the CliOptions
class has this for positional parameters:
/** List of file to validate. */
@Parameters(arity = "1..*", description = "One or more source files to verify")
private List<File> files;
Depending on the other options, the actual processing is delegated to various other classes, like AstTreeStringPrinter.printFileAst
, XpathUtil.printXpathBranch
, DetailNodeTreeStringPrinter.printFileAst
, etc.
So perhaps all these places need to be changed.
But I notice that CheckStyle already has an abstraction FileText
that seems to be responsible for extracting the contents from a File
object.
It appears to me that the FileText
class (readFile
method) is a good candidate to add this logic:
// if end user specified `-` as the path, read from STDIN instead of reading from a file
final InputStream stream = ("-".equals(inputFile.toString())
? System.in
: Files.newInputStream(inputFile.toPath());
from checkstyle.
I added an example to picocli-examples
:
https://github.com/remkop/picocli/blob/main/picocli-examples/src/main/java/picocli/examples/stdin/PrintFirstLine.java
from checkstyle.
Can you update your post and give an example command line of what you are looking for.
We use https://picocli.info/ , so we can and only support whatever they provide us.
from checkstyle.
@remkop , I went through doc I didn't not find this possibility explicitly.
Do you know how to archive something like user requesting above?
from checkstyle.
@remkop , thanks a lot for all very detailed comments. Very helpful.
Since checkstyle supports several file types (java, properties..), maybe a parameter --stdin-filename
after a bit of thoughts on this .... there are Checks that validate filename against top class, and there are something for folders that contains a target file, for property file validation (TranslationCheck) it even need multiple files.
This feature might work and but it will be very prone to false positives in general usage, dependeds with what config(set of Checks) you will run it.
you can use suggestion above and hack some solution and we can consider it for review. But it looks like it will be much easier to user content to temp file and run existing CLI, as you know context of execution, you might be able to filter out false positives that this solution prone to.
That would allow linting as the user types even unsaved files without going through temporary files.
One more problem is file has to be compile-able. https://checkstyle.org/writingchecks.html#Limitations
Code has to be compilable by javac to get valid violations. If it is not, you can get hard to understand parse errors.
sometime is works on bad java files but Checks are go wild. Compilation with no errors is hard limitation for us.
This point does not a blocker for this issue, it might be a problem for task what you try solve. javac
must pass before you put file to checkstyle CLI.
from checkstyle.
Right. Thank you for taking the time to research all the ins and outs of the idea. I understand all the constraints now.
I didn't realize that some checks go and check other files on disk... That seems to be the biggest hurdle, because it would have to be tracked, which checks are compatible, which not, added complexity...
Ok, then I'll close this issue for now, I'll consider whether to make a PR, but given all the constraints you've quoted, I likely won't... Thank you again for all the effort in checking this out, and for the tool itself which is really super useful!
from checkstyle.
Related Issues (20)
- How to exclude java-Files that contain @Generated-Annotation? HOT 4
- Improve documentation - how to add usage of `var` to check `IllegalType`? HOT 6
- Column number in `DetailNode` should start with 1 HOT 16
- LITERAL_DEFAULT token support in RightCurlyCheck
- False Negative of ClassFanOutCheck with "new" Keyword HOT 6
- MagicNumberCheck NPE when ignoring field declarations HOT 11
- Parse exception for RAW string template (Java 21+) HOT 3
- IllegalType Not Working For Annotation Using FQN HOT 3
- Remove Support for String Template Syntax
- Re-enable and Monitor `YAMLSchemaValidation` inspection HOT 6
- Resolve `TailRecursion` inspection violations by replacing tail recursive calls HOT 4
- log() method incorrectly calculates the column number when Tabs are used HOT 8
- WhitespaceAround reports a violation when switch expression is passed as a method argument HOT 2
- Parameter name should be provided after @param tag HOT 1
- Please REMOVE most badges from the README HOT 5
- Please, add a small section to the README on how to install and use this tool HOT 5
- Test to ensure website checks/filters are in alphabetical order
- Fix performance test HOT 3
- build failure due to maven.plugin.json HOT 2
- Github generate site fails to generate links with anchors.
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 checkstyle.