Giter Site home page Giter Site logo

pantajoe / vscode-elixir-credo Goto Github PK

View Code? Open in Web Editor NEW
28.0 28.0 5.0 1.35 MB

VSCode support for Elixir Linter 'Credo'.

Home Page: https://marketplace.visualstudio.com/items?itemName=pantajoe.vscode-elixir-credo

License: MIT License

TypeScript 98.77% JavaScript 1.14% Elixir 0.09%
credo elixir linter vscode-extension

vscode-elixir-credo's People

Contributors

dependabot[bot] avatar lvl3 avatar pantajoe avatar wceolin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

vscode-elixir-credo's Issues

Add support for mix credo diff

I'm currently using mix credo diff which was introduced in 1.6.0. Sadly this plugin doesn't work with that command (and all other elixir linters at the time of this writing). Here's an example of the new output:

{
  "diff": {
    "fixed": [],
    "new": [
      {
        "category": "refactor",
        "check": "Credo.Check.Refactor.VariableRebinding",
        "column": 5,
        "column_end": 12,
        "filename": "...",
        "line_no": 78,
        "message": "Variable \"changes\" was declared more than once.",
        "priority": 4,
        "scope": "...",
        "trigger": "changes"
      }
    ],
    "old": []
  }
}

Add support for project subdirectories

Right now this extension only works if I open the elixir directory as the root directory of the vscode workspace.
It will be helpful to have a configuration setting that allows me to define in which subdirectory the elixir root folder is.
The problem arises when I have to work both at the frontend and backend at the same time.

Tag filter options

I have a credo check that compares the module name to the file name to ensure they match. This check always fails when run from vscode, since the file name credo sees is 'stdin'. Currently, to work around this, I have to duplicate my whole credo config except for this one check, and tell vscode-elixir-credo to use the duplicated config

It would be preferable to simply set tags: [:__initial__, :no_editor] on the faulty check and tell vscode-elixir-credo to pass --checks-without-tag no_editor to credo

I can image a scenario exists where the inverse option, --checks-with-tag some_tag, is useful as well

Wrong errors reported in VSCode

I have set up a new Phoenix project, added credo as a dependency, then installed this VSCode extension to get info/hints on code style violations.

But, inside VSCode I get a squiggly line on every defmodule with a false positive, for example:

Test files should end with .exs (warning:Credo.Check.Warning.WrongTestFileExtension)
Simulation.Core.Vector2D

Which in itself is wrong, since that's not a test file (lib/simulation/core/vector_2d.ex).
I've tried restarting the extension host, and the Elixir language server but the spurious report persist.

Running mix credo --strict from the CLI does not yield those errors, so I think it's related to the extension or configuration maybe?

Any recommendations or pointers on what could be wrong, or how to debug what's going on?

Cheers,
VA

“.credo.exs file does not exist” in project located in sub directory

Background
I have an app with the following structure:

:.
├───angular
│ └───src
├───phoenix
│ └───mix.exs
│ └───.mix.lock
│ └───.credo.exs
...
When working with my project, I usually open the root folder of the project and work in the desired application folder from there.

My .credo.exs. file is the default one generated by mix credo gen.config and I have {:credo, "~> 1.7", only: [:dev, :test], runtime: false}, in my phoenix/mix.exs file.

I have also installed credo and its dependencies using:

mix archive.install hex credo
mix archive.install hex bunt
mix archive.install hex jason
So I am sure I have all the dependencies installed.

I also launch VSCode with code . using Linux zsh to make sure I get all the ENV vars from the shell loaded.

Problem
The issue here is that no matter what I do, I always get the .credo.exs file does not exist. Ignoring .... no matter what I do.
I configured "elixir.credo.configurationFile": "phoenix/.credo.exs" and have the same issue.

Questions
How can I fix this?
Maybe there can be config for project dir "elixir.credo.projectDir": "phoenix"? Like "elixirLS.projectDir": "phoenix" or "credo.projectDir": "phoenix" in https://github.com/adamzapasnik/vscode-credo-linter

Extension errors when CMD/CTRL+hovering symbols from other files

When holding CMD/CTRL and hovering a module or function from another file, it seems like Credo tries to run on that file but fails, causing this error message to be displayed as a notification:

Command /Users/jamin/.asdf/shims/mix credo returns empty output! Please check your configuration. Did you add or modify your dependencies? You might need to run mix deps.get or recompile.

The error only occurs when the file of the hovered symbols is not open:

Screen.Recording.2021-11-30.at.11.12.30.AM.mov

The error does not occur when the file is already open:

Screen.Recording.2021-11-30.at.11.12.50.AM.mov

This is the debug log (elixir.credo.enableDebug set to true) when duplicating the error:

> Retreiving credo information: Executing credo command `/Users/jamin/.asdf/shims/mix credo info --format json --verbose` for /Users/jamin/Projects/vscode_elixir_issue/lib/other_module.ex in directory /Users/jamin/Projects/vscode_elixir_issue

> Removing linter messages and cancel running linting processes for /Users/jamin/Projects/vscode_elixir_issue/lib/other_module.ex.

> Command `/Users/jamin/.asdf/shims/mix credo` returns empty output! Please check your configuration. Did you add or modify your dependencies? You might need to run `mix deps.get` or recompile.

The extension still functions correctly (linting open Elixir files), though.

Steps to Reproduce

  1. Create a new Elixir project with mix new.
  2. Install Credo and set up config with mix credo.gen.config.
  3. Create a new file and module (OtherModule) with a function (some_function).
  4. Reference that function in another file and module (MainModule).
  5. Close all files except the one containing MainModule.
  6. Hold CMD/CTRL and hover over OtherModule or some_function.
  7. Observe the "returns empty output" error in a notification.

Credo.Check.Refactor.ModuleDependencies breaks analysis

With Credo.Check.Refactor.ModuleDependencies enabled and a file that triggers this check, no issues show up on VSCode since the parsing fails on parser.tsx#L22 with trigger.replace is not a function.

This happens because the trigger for this check is an array, ie:

{
  category: "refactor",
  check: "Credo.Check.Refactor.ModuleDependencies",
  column: null,
  column_end: null,
  filename: "stdin",
  line_no: 1,
  message: "Module has too many dependencies: 13 (max is 10)",
  priority: 3,
  scope: "MyService.TooManyDeps",
  trigger: [
    "OK",
    "DateTime",
    "Atom",
    "Float",
    "Timex",
    "MyService.Dep1",
    "Enum",
    "Map",
    "MyService.Dep2",
    "MyService.Dep3",
    "MyService.Dep4",
    "MyService.Dep5",
    "List",
  ],
}

A quick fix would be to change the check on L19 to if (!trigger || typeof trigger !== 'string') return null; but maybe there's a better way to go about this.

".credo.exs file does not exist. Ignoring..." (Windows 10)

VSCode Info

Version: 1.56.0-insider (user setup)
Commit: 845efe5d8e31079cc858131c95c36103d9439e74
Date: 2021-04-09T09:50:06.816Z
Electron: 11.4.2
Chrome: 87.0.4280.141
Node.js: 12.18.3
V8: 8.7.220.31-electron.0
OS: Windows_NT x64 10.0.19042


Trying to use this plugin but I'm getting a constant .credo.exs file does not exist. Ignoring... in any Elixir file in my project - even the .credo.exs. Even setting elixir.credo.configurationFile in my settings doesn't change anything.

image

".credo.exs file does not exist. Ignoring..." (warning)

Hi!

I still get ".credo.exs file does not exist. Ignoring..." warning after installing Credo in VS Code on Windows 11 Pro.
The problem is that there is some Credo inspection that requires .credo.exs in the root of the mix project.
Right after I create such file (empty inside), the warning is gone.

Could you please turn off this inspection, so there is no need to create that unnecessary .credo.exs file?

Configuration file setting doesn't work

Hi! 👋

Big thanks for your work on the extension.

There is one problem with extension configuration through credo configuration file.

I've set configurationFile option into settings.json file, like this:

"elixir.credo.configurationFile": "config/.credo.exs"

and have these settings in .credo.exs.

%{
  configs: [
    %{
      name: "default",
      files: %{
        included: ["mix.exs", "lib/"],
        excluded: ["test/"]
      }
    }
  ]
}

When I run mix credo it works as expected, but in vscode, I have warnings in test modules, that Modules should have a @moduledoc tag.
Screenshot 2021-01-31 at 13 29 43

Am I doing something wrong?

Doesn't find the right root folder on multi-apps projects

Hello! I've seen #289 and have a similar issue, but the proposed solution would not work for me.

My project folder is structured as the following:

  • mix.exs (with credo installed here)
  • .credo.exs
  • apps/
    • app_foo (with its own mix.exs without credo)
    • app_bar (with its own mix.exs without credo)
    • and many more apps structured similarly

So I have many apps, but I want consistency in the whole codebase. So installing credo in every mix.exs doesn't work and having a .credo.exs in every app doesn't either.

But when I'm editing files in any of the apps, the extension finds the mix.exs in the file's app, uses that folder as the project folder, and doesn't find credo installed because it's further up.

For now I'm working around this by modifying the extension code manually so it searches for ".credo.exs" instead of "mix.exs", but I could see this not working for other projects. I think having a configuration to manually specify the project folder would help fix the times where the automatic discovery doesn't work as needed.

Windows 10: 'mix' is not executable

Version: 1.54.2 (user setup)
Commit: fd6f3bce6709b121a895d042d343d71f317d74e7
Date: 2021-03-11T00:56:19.848Z
Electron: 11.3.0
Chrome: 87.0.4280.141
Node.js: 12.18.3
V8: 8.7.220.31-electron.0
OS: Windows_NT x64 10.0.19041

I have 'C:\Program Files (x86)\Elixir\bin' in path, 'mix' is in that path and i can run 'mix credo' in terminal, but when i try to use Elixir Linter (Credo) extension it prints this error message:

`C:\Program Files (x86)\Elixir\bin\mix` is not executable.
        Try setting the option in this extension's configuration "elixir.credo.executePath"
        to the path of the mix binary.

Changing "elixir.credo.executePath" does not help.

Add option to re-lint as a vscode command and not on save

Hello! As a user of auto-save I currently find the plugin hard to work with. Since it activates on every save a lot of times the file is not ready to be linted and an error message pops up. An option to keybind the re-linting of a file would be a huge quality of life improvement for programmers using auto-save.

Add a option to only run credo if mix.exs exists

When I'm editing a simples .exs the plugin will try to run the mix credo, but mix.exs doesn't exists:

Command `/usr/local/bin/mix credo` returns empty output! Please check your configuration. Did you add or modify your dependencies? You might need to run `mix deps.get` or recompile.

Add config option to disable notification prompts regarding error parsing output

First, thank you so much for a plugin I use on a regular basis. Projects like this make the world 🌐 go round.

I frequently get an error notification from this plugin. Usually around the error:

Error on parsing output (It might be non-JSON output): " 11:13:24.745 [notice] SIGTERM received - shutting down "

I'd prefer to go to the plugin output to see this error. Particularly since I don't have to do anything for the plugin/credo to restore itself. Having no ability to mute this error notification is a frequent annoyance for me.

“.credo.exs file does not exist” in Umbrella project

Background

I have an umbrella app with the following structure:

:.
├───mix.exs
├───.mix.lock
├───.credo.exs
├───apps
│   └───app1
...

When working with my umbrella project, I usually open the root folder of the project and work in the desired application from there.

My .credo.exs. file is the default one generated by mix credo gen.config and I have {:credo, "~> 1.6", only: [:dev, :test], runtime: false}, in my root's mix.exs file.

I have also installed credo and its dependencies using:

mix archive.install hex credo
mix archive.install hex bunt
mix archive.install hex jason

So I am sure I have all the dependencies installed.

I also launch VSCode with code . using Windows cmd to make sure I get all the ENV vars from the shell loaded.

Problem

The issue here is that no matter what I do, I always get the .credo.exs file does not exist. Ignoring .... no matter what I do.

To try and fix my issues I read this post:

https://elixirforum.com/t/configure-credo-to-use-global-credo-exs-file/2707

However this wont do it for me. Not only do I still get the error once I get inside the individual applications, it also does not fit with my workflow, as I mostly work with the root directory open.

Questions

How can I fix this?

[VSCode] Error "command `/usr/bin/mix credo` returns empty output"

Hi,
I've been trying to install this extension but encountered the error above. Here's full version:

command `/usr/bin/mix credo` returns empty output! please check configuration.
        Did you add or modify your dependencies? You might need to run `mix deps.get` or recompile.

That's weird because I already have credo installed and I can run mix credo manually in terminal without problem.

Could you please have a look at this? Thank you for your great work.

Can't work with credo v1.6.7

Details

I trying to use the extension with latest version of credo but when I put the configuration described in creed's README and save an example file, VSCode gives an error and a warn:

image

image

Steps to reproduce

  1. add extension to VSCode
  2. create new project using command mix new example and access it with vscode
  3. add the credo to project as defined in docs
     defp deps do
       [
         {:credo, "~> 1.6", only: [:dev, :test], runtime: false}
       ]
     end
  4. open the first file of project in lib/example.ex and press command + s some times

System Info

  • SO: MacOS Venntura v13.2.1
  • VSCode: v1.75.1
  • Credo (Elixir Linter): v0.8.2

Other info's

When install credo v1.5.x the extension works correctly

Linter doesn't show anything in umbrella application on windows 10

Hello!

I have installed credo linter for Elixir Phoenix umbrella app.
mix credo works fine in console.
But, unfortunately, in vscode linter doesn't show any messages.

Here is my vscode setup:

Version: 1.55.2 (system setup)
commit: 3c4e3df9e89829dce27b7b5c24508306b151f30d
Date: 2021-04-13T09:35:57.887Z
Electron: 11.3.0
Chrome: 87.0.4280.141
Node.js: 12.18.3
V8: 8.7.220.31-electron.0
OS: Windows_NT x64 10.0.18363

.credo.exs file was generated by mix credo.gen.config command.

I have created some module in apps/ folder, like this:
http://prntscr.com/11iklcd

and see strange behavior in terminal:
http://prntscr.com/11ikhyy

No linting tips shown.

And in non-umbrella app everything works as expected:
http://prntscr.com/11ikrzc

I would appreciate any help to solve this question.
Thanks!

Displaying of credo warnings throws "Illegal Argument" error

My credo warnings weren't showing in the opened code file, but I knew there were some after running mix credo from the command line. So, I opened the Help > Toggle Developer Tools and saw that the following errors were logged:

mainThreadExtensionService.ts:59 [[object Object]]Illegal argument: character must be non-negative
$onExtensionRuntimeError @ mainThreadExtensionService.ts:59
_doInvokeHandler @ rpcProtocol.ts:417
_invokeHandler @ rpcProtocol.ts:402
_receiveRequest @ rpcProtocol.ts:318
_receiveOneMessage @ rpcProtocol.ts:245
(anonymous) @ rpcProtocol.ts:110
fire @ event.ts:622
fire @ ipc.net.ts:468
_receiveMessage @ ipc.net.ts:821
(anonymous) @ ipc.net.ts:660
fire @ event.ts:622
acceptChunk @ ipc.net.ts:241
(anonymous) @ ipc.net.ts:202
I @ ipc.net.ts:32
emit @ events.js:315
addChunk @ _stream_readable.js:295
readableAddChunk @ _stream_readable.js:271
Readable.push @ _stream_readable.js:212
onStreamRead @ internal/stream_base_commons.js:186

mainThreadExtensionService.ts:60 Error: Illegal argument: character must be non-negative
	at Object.k [as illegalArgument] (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:5)
	at new m (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:81)
	at new m (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:81)
	at new S (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:81)
	at new S (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:81)
	at Function.parseCredoIssue (/Users/pullrich/.vscode/extensions/pantajoe.vscode-elixir-credo-0.2.0/out/CredoParser.js:18)
	at /Users/pullrich/.vscode/extensions/pantajoe.vscode-elixir-credo-0.2.0/out/CredoParser.js:8
	at Array.map (<anonymous>)
	at Function.parseCredoOutput (/Users/pullrich/.vscode/extensions/pantajoe.vscode-elixir-credo-0.2.0/out/CredoParser.js:8)
	at /Users/pullrich/.vscode/extensions/pantajoe.vscode-elixir-credo-0.2.0/out/CredoProvider.js:34
	at ChildProcess.exithandler (child_process.js:319)
	at ChildProcess.emit (events.js:315)
	at maybeClose (internal/child_process.js:1021)
	at Socket.<anonymous> (internal/child_process.js:443)
	at Socket.emit (events.js:315)
	at Pipe.<anonymous> (net.js:674)

The credo warning that should have been shown here was the following:

Web.StripeWebhookController                                                                                                                                          
┃ 
┃   [W] Category: warning 
┃    ↗  Priority: high 
┃ 
┃       Module attribute @webhook_signing_key makes use of unsafe Application configuration call Application.get_env/2
┃       lib/web/controllers/stripe_webhook/stripe_webhook_controller.ex:6 (Web.StripeWebhookController)
┃ 
┃    __ CODE IN QUESTION
┃ 
┃     4   require Logger
┃     5 
┃     6   @webhook_signing_key Application.get_env(:stripity_stripe, :webhook_signing_key)
┃       
┃    __ WHY IT MATTERS
┃ 
┃       Module attributes are evaluated at compile time and not at run time. As
┃       a result, certain configuration read calls made in your module attributes
┃       may work as expected during local development, but may break once in a
┃       deployed context.
┃       
┃       This check analyzes all of the module attributes present within a module,
┃       and validates that there are no unsafe calls.
┃       
┃       These unsafe calls include:
┃       
┃       - `Application.fetch_env/2`
┃       - `Application.fetch_env!/2`
┃       - `Application.get_all_env/1`
┃       - `Application.get_env/3`
┃       - `Application.get_env/2`
┃       
┃       As of Elixir 1.10 you can leverage `Application.compile_env/3` and
┃       `Application.compile_env!/2` if you wish to set configuration at
┃       compile time using module attributes.
┃ 
┃    __ CONFIGURATION OPTIONS
┃ 
┃       You can disable this check by using this tuple
┃ 
┃         {Credo.Check.Warning.ApplicationConfigInModuleAttribute, false}
┃ 
┃       There are no other configuration options.
┃ 
┃                                                          

I'm not entirely sure why displaying this warning threw an error unfortunately. Can I help you somehow with replicating this error maybe?

Error mix credo returned empty output

I've received a lot of times errors like this one:

image

The curious thing is, in my settings I have:

"elixir.credo.executePath": "/home/rafael/.asdf/installs/elixir/1.11.3/bin/mix"

So, my path is one, but the error shows another one. Seems that the config is not being respected 🤔

I have already tried with /home/rafael/.asdf/shims/mix as well but the error remains the same.

Do you have any clues that something that I should do to stop the error? Or maybe this could be a bug?

I'm currently using asdf to manage my elixir versions.

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.