Giter Site home page Giter Site logo

Comments (4)

mgrebenets avatar mgrebenets commented on May 25, 2024 1

It still happens.
What I noticed is when I start the project and it does an initial lint, it picks up all the problems correctly.
Looks like it may be using the default config sitting in the project root.

But as soon as I navigate into the specific file it seems to re-run SwiftLint this time with different configs (or without them?).
Is there a way I could configure extension to print verbose output somewhere to see what commands it invokes when I navigate between files?

from vscode-swiftlint.

mgrebenets avatar mgrebenets commented on May 25, 2024 1

As far as I could track it down when listing the entire workspace the extension passes the project root path to SwiftLint, which allows SwiftLint to find parent/child config files.

When going into an editor window it ends up using --use-stdin flag with current working directory set to the parent directory of the currently opened file. It also passes the whole file via stdin.

E.g. something like this:

cd sub/dir
cat file.swift | swiftlint --use-stdin

I suspect it's intended behavior of SwiftLint.
When we pass it Swift code via stdin it shouldn't really care what's the current working directory. We don't pass it any actual path to figure out where to look for config file either.

I understand that extension wants to pass file content rather than the file to have an option to lint currently selected text vs the whole file.

Maybe there's some magic the extension could add?
E.g. look up for for first .swiftlint.yml in parent directories within the workspace.
Or maybe always run swiftlint command passing the file path.

from vscode-swiftlint.

vknabel avatar vknabel commented on May 25, 2024

Hey @mgrebenets!

Thanks for the great issue description!

In theory 1.4.0 and #23 should've added nested config support if swiftlint.configSearchPaths is empty. But I still found the outdated default value [".swiftlint.yml"] within the code base.

Does 1.4.3 fix your issue?

from vscode-swiftlint.

vknabel avatar vknabel commented on May 25, 2024

I can't thank you enough! I actually wrote multiple comments just to delete everything before sending. I always found a new edge case.

When running swiftlint --use-stdin we'd need to get into the current file's parent directory which contains the most specific .swiftlint.yml-file and then lint. This would lead to mostly correct results.

But this would break the behaviour of excluded! And even explicitly passing --config stops nested configurations from working correctly (and I try to avoid parsing all configs).

Instead I decided to only lint files after being saved. Currently it is only possible to view the actually executed commands by cloning this repo and starting the debugger. In the case of this issue the executed command would look something like:

cd /Users/vknabel/Desktop/Swiftlint &&  SCRIPT_INPUT_FILE_0='dir/dir/Example.swift' SCRIPT_INPUT_FILE_COUNT='1' '/usr/local/bin/swiftlint'  '--use-script-input-files' '--quiet' '--reporter' 'json'

The new behaviour is available as 1.4.4. Can you test the new release?


In the mid to long term, I try to re-add the lint-while-typing-feature. But I guess this takes a little bit more work.

from vscode-swiftlint.

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.