Code Monkey home page Code Monkey logo

Comments (7)

emmanueltouzery avatar emmanueltouzery commented on June 11, 2024 1

I have updated the issue description!

from checkstyle.

remkop avatar remkop commented on June 11, 2024 1

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.

remkop avatar remkop commented on June 11, 2024 1

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.

rnveach avatar rnveach commented on June 11, 2024

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.

romani avatar romani commented on June 11, 2024

@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.

romani avatar romani commented on June 11, 2024

@remkop , thanks a lot for all very detailed comments. Very helpful.

@emmanueltouzery ,

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.

emmanueltouzery avatar emmanueltouzery commented on June 11, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.