Skip to content

Commit

Permalink
feat(cache): Store cached luacheck values per-version in case of changes
Browse files Browse the repository at this point in the history
  • Loading branch information
arichard4 committed Aug 4, 2022
1 parent 815cf79 commit 88d127d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
6 changes: 4 additions & 2 deletions spec/config_spec.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
local lfs = require "lfs"

local luacheck = require "luacheck"
local config = require "luacheck.config"
local fs = require "luacheck.fs"
local cur_dir = lfs.currentdir()
local P = fs.normalize
local function AP(p) return P(fs.join(cur_dir, p)) end
local function cache_dir(p) return P(fs.join(cur_dir, p, luacheck._VERSION)) end

local function nest(dir, func)
local backed = false
Expand Down Expand Up @@ -172,7 +174,7 @@ describe("config", function()
formatter = "helper.fmt",
formatter_anchor_dir = P(cur_dir),
jobs = false,
cache = AP("something.luacheckcache"),
cache = cache_dir("something.luacheckcache"),
include_files = {
AP("foo"),
AP("bar")
Expand All @@ -197,7 +199,7 @@ describe("config", function()
formatter = "helper.fmt2",
formatter_anchor_dir = P(cur_dir),
jobs = false,
cache = AP("something.luacheckcache"),
cache = cache_dir("something.luacheckcache"),
include_files = {
AP("foo"),
AP("bar"),
Expand Down
9 changes: 7 additions & 2 deletions src/luacheck/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ local fs = require "luacheck.fs"
local globbing = require "luacheck.globbing"
local standards = require "luacheck.standards"
local utils = require "luacheck.utils"
local luacheck = require "luacheck"

local config = {}

Expand Down Expand Up @@ -475,12 +476,16 @@ function ConfigStack:get_top_options()
if conf.options.cache ~= nil then
if conf.options.cache == true then
if not res.cache then
res.cache = fs.normalize(fs.join(last_anchor_dir or current_dir, cache.get_default_dir()))
res.cache = fs.normalize(fs.join(
last_anchor_dir or current_dir,
cache.get_default_dir(),
luacheck._VERSION
))
end
elseif conf.options.cache == false then
res.cache = false
else
res.cache = fs.normalize(fs.join(anchor_dir, conf.options.cache))
res.cache = fs.normalize(fs.join(anchor_dir, conf.options.cache, luacheck._VERSION))
end
end
end
Expand Down

0 comments on commit 88d127d

Please sign in to comment.