Skip to content

Commit

Permalink
src: support NO_COLOR environment variable
Browse files Browse the repository at this point in the history
NO_COLOR is a de-facto standard environment variable for disabling
colors, see [1]:

> Command-line software which adds ANSI color to its output by default
> should check for a NO_COLOR environment variable that, when present and
> not an empty string (regardless of its value), prevents the addition of
> ANSI color.

The patch disables coloring when NO_COLOR is not empty.

1. https://no-color.org/
  • Loading branch information
ligurio committed Oct 24, 2023
1 parent 24747f5 commit d5a5529
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/luacheck/format.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ local utils = require "luacheck.utils"
local format = {}

local color_support = not utils.is_windows or os.getenv("ANSICON")
-- Disable colors when NO_COLOR is set, see https://no-color.org/.
color_support = color_support and not os.getenv("NO_COLOR")

local function get_message_format(warning)
local message_format = assert(stages.warnings[warning.code], "Unkown warning code " .. warning.code).message_format
Expand Down

0 comments on commit d5a5529

Please sign in to comment.