Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dotenv syntax highlighting support #4873

Closed
probablykasper opened this issue May 30, 2020 · 10 comments · Fixed by #4922
Closed

dotenv syntax highlighting support #4873

probablykasper opened this issue May 30, 2020 · 10 comments · Fixed by #4922

Comments

@probablykasper
Copy link

Feature request to add syntax highlighting support for .env files. This was discussed in #3717 in 2017, but seems to have been closed without reason.

The .env syntax is used to define environment variables, and it's very commonly used with Node.js, Docker and probably others.

Although .env is often used for passwords, it's also commonly used for general config files which are fine to commit. Some repos have a private .env file and one that is committed - For example Vue and React use .env and .env.local. In addition to that, some repos have .env-sample, .env.example, or a code block in README.md, to show how private .env files should look.

References:

  • package.json of the VSCode dotenv extension which lists all the .env file extensions it supports.
  • dotenv npm package
@lildude
Copy link
Member

lildude commented Jun 6, 2020

As Linguist relies upon community contributions to address such requests, we'd welcome a PR that adds support or attributes the files to an already defined language.

@stale
Copy link

stale bot commented Jul 6, 2020

This issue has been automatically marked as stale because it has not had activity in a long time. If this issue is still relevant and should remain open, please reply with a short explanation (e.g. "I have checked the code and this issue is still relevant because ___."). Thank you for your contributions.

@stale stale bot added the Stale label Jul 6, 2020
@probablykasper
Copy link
Author

Seems fair to keep this open as dotenv is a common syntax

@stale stale bot removed the Stale label Jul 6, 2020
@smola
Copy link
Contributor

smola commented Jul 10, 2020

We might want to classify these as Shell and get proper syntax highlighting. As far as I know, .env is kind of inspired on shell configuration files and sometimes will even contain full sh/bash syntax.

You can find many real world examples of .env and *.env files which are predominantly shell scripts:

Even the usual usage with just key=value and # comments is a subset of POSIX sh syntax.

@probablykasper
Copy link
Author

@smola I think it would be best to keep dotenv separated from shell syntax.

The .env files with shell scripts you linked use hashbangs like #!/bin/bash. Is it possible for linguist to detect highlighting from that, and otherwise use dotenv syntax?

For reference, the dotenv npm package lists it's syntax rules, except variable expansion which is added using the dotenv-expand package.

@smola
Copy link
Contributor

smola commented Jul 10, 2020

@probablycorey Please, see the description of this PR: #4922

dotenv is not something new from the Node.js world. It's a convention to somewhat standarize a subset of shell script syntax to allow parsing from different languages. As far as I can tell, all dotenv variants (there are many, supporting different syntax) are strict subsets of Bash. So any highlighter supporting Bash scripts should work with all of them.

Also, the syntax supported by the Node package you are linking is far more limited than the syntax supported by the Ruby package (https://github.com/bkeepers/dotenv), the PHP package, etc. If we supported npm's dotenv syntax only, it would be broken with Ruby's dotenv syntax. But AFAIK shell syntax will work with all of them.

@smola
Copy link
Contributor

smola commented Jul 10, 2020

Well, actually this syntax from the npm package is not valid Bash: JSON={"foo": "bar"}...

@probablykasper
Copy link
Author

@smola Ah got it, didn't realize there are variants from the npm package's implementation. Makes sense to use shell syntax in that case

@stale
Copy link

stale bot commented Aug 9, 2020

This issue has been automatically marked as stale because it has not had activity in a long time. If this issue is still relevant and should remain open, please reply with a short explanation (e.g. "I have checked the code and this issue is still relevant because ___."). Thank you for your contributions.

@stale stale bot added the Stale label Aug 9, 2020
@smola
Copy link
Contributor

smola commented Aug 10, 2020

Bump, not stale, there is an active PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants