pantajoe / vscode-elixir-credo Goto Github PK
View Code? Open in Web Editor NEWVSCode support for Elixir Linter 'Credo'.
Home Page: https://marketplace.visualstudio.com/items?itemName=pantajoe.vscode-elixir-credo
License: MIT License
VSCode support for Elixir Linter 'Credo'.
Home Page: https://marketplace.visualstudio.com/items?itemName=pantajoe.vscode-elixir-credo
License: MIT License
The credo docs specify that the .credo.exs
config file can live in either the root project folder or the config
folder (https://hexdocs.pm/credo/config_file.html). Either of these locations should be valid default options.
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:
mix new example
and access it with vscode defp deps do
[
{:credo, "~> 1.6", only: [:dev, :test], runtime: false}
]
end
lib/example.ex
and press command + s
some timesWhen install credo v1.5.x the extension works correctly
Hello guys!
I've found an inconsistency when running mix credo
with the --read-from-stdin
option that seems to be used by this extension, and it looks that we have to pass the filename together with it to fix that, as pointed out in this comment.
If you guys agree, I think I can do it myself as it seems quite simple.
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!
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": []
}
}
Currently, this extension cannot be installed from VSCodium interface, and it would be great to do so.
As far as I have read in VSCodium documentation (https://github.com/VSCodium/vscodium/blob/master/DOCS.md#extensions-marketplace) there is a wiki documenting the process https://github.com/eclipse/openvsx/wiki/Publishing-Extensions
Hope you could consider doing it.
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.
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.
How can I fix this?
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:
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.
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
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?
Hello! your extension is great!
But why did choose not to display Refactor
in problem list, and not to underline it in file? (https://github.com/pantajoe/vscode-elixir-credo/blob/main/src/CredoParser.ts#L28) As u can see on screen there is information about in credo output:
Also, on first screen there is underlining (TODO comment), when in credo output there is no start/end line column, it will be great to underline THE HOLE string in that case)
TY!
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.
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
These updates are awaiting their schedule. Click on a checkbox to get an update now.
@biomejs/biome
, @types/chai
, @types/node
, @types/vscode
, @vscode/test-electron
, gettext
, glob
, husky
, lint-staged
, mocha
, node
, pnpm
, postgrex
, typescript
, vscode
)These are blocked by an existing closed PR and will not be recreated unless you click a checkbox below.
.tool-versions
node 20.15.0
.github/workflows/ci.yml
actions/checkout v4
actions/setup-node v4
.github/workflows/publish.yml
actions/checkout v4
actions/setup-node v4
src/test/fixtures/mix.exs
phoenix ~> 1.7.14
phoenix_ecto ~> 4.6
ecto_sql ~> 3.11
postgrex >= 0.18.0
phoenix_html ~> 2.14
phoenix_live_reload ~> 1.5
telemetry_metrics ~> 0.6
telemetry_poller ~> 0.5
gettext ~> 0.24
jason ~> 1.4
plug_cowboy ~> 2.7
credo ~> 1.7
package.json
@biomejs/biome 1.8.2
@commitlint/cli ^19.3.0
@commitlint/config-conventional ^19.2.2
@total-typescript/shoehorn ^0.1.2
@types/chai ^4.3.16
@types/chai-as-promised ^7.1.8
@types/glob ^8.1.0
@types/mocha ^10.0.7
@types/node ^20.14.8
@types/sinon ^17.0.3
@types/sinon-chai ^3.2.12
@types/vscode ^1.90.0
@vscode/test-electron ^2.4.0
chai <5.0.0
chai-as-promised ^7.1.2
chai-change ^2.1.2
glob ^10.4.2
husky ^9.0.11
lint-staged ^15.2.7
mocha ^10.4.0
sinon ^18.0.0
sinon-chai ^3.7.0
typescript ^5.5.2
vscode ^1.90.2
pnpm 9.4.0
biome.jsonc
@biomejs/biome 1.8.2
I've received a lot of times errors like this one:
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.
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
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.
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.
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?
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.
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 runmix deps.get
or recompile.
The error only occurs when the file of the hovered symbols is not open:
The error does not occur when the file is already open:
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.
mix new
.mix credo.gen.config
.OtherModule
) with a function (some_function
).MainModule
).MainModule
.OtherModule
or some_function
.After saving in vscode with this extension enabled, recompile
in IEx session does not work, and the new code will not be loaded. This forces you to quit IEx completely and start a new session.
Hi @pantajoe first of all, thank you for such a neat tool. However i have just one problem, if i have it enabled at the same time I enable the elixirtools extesion for autocomplete purposes, now i cannot see my Elixir autocompletion suggestions. It is so frustrating that i cannot have the best of both worlds. Could you suggest a set of linters and formatters and language servers that best work with your extension with little to no conflict, or otherwise could you check on what is the bug creating this conflict with autocompletion.
Hi, it's over a year since the last commit to this repo, and issues and PRs have lately gone without a response.
@pantajoe this isn't a complaint - in fact, thanks for contributing this extension! - but do you plan to resume maintaining the extension or to deprecate it?
I've been hit by some of the open issues around looking for .credo.exs
in the wrong places, and I'm potentially interested in contributing a fix beyond the existing blunt option to suppress warnings, but looking at this repo I'm not sure if contributions would ever be merged. Alternatively, I'm potentially interested in taking over maintenance if you're too busy (but as far as I can tell, there's no clean way to transfer ownership of a published vscode extension, so some headscratching required there...)
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.
Right now, we use JSON.parse
in conjunction with as
in TypeScript which is very unsafe. I'd be better to use the package zod
for proper JSON schema valiation.
Right, now in the Linter
class, the command mix credo info
(which is used to determine whether an actively edited file should be linted with credo) is executed on every lint request.
That's very inefficient and therefore should be stored in the a workspace project's configuration and only re-fetched when the credo configuration changes.
Found multiple files (./.credo.exs,/Users/austin/dev/kinetic/lowes/.credo.exs) will use ./.credo.exs
Those are the same file (it also applied when I was using the default, .credo.exs
).
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
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.
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.
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.
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.
Am I doing something wrong?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.