Skip to content

Commit

Permalink
Refactor globbing module
Browse files Browse the repository at this point in the history
Turn class into a regular module.
  • Loading branch information
mpeterv committed Jul 17, 2015
1 parent 1b3fa55 commit c968312
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 26 deletions.
2 changes: 1 addition & 1 deletion install.lua
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ for _, filename in ipairs {
"format.lua",
"version.lua",
"fs.lua",
"globber.lua",
"globbing.lua",
"utils.lua",
"argparse.lua"} do
copy("src" .. dirsep .. "luacheck" .. dirsep .. filename, luacheck_lib_dir)
Expand Down
2 changes: 1 addition & 1 deletion luacheck-scm-1.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ build = {
["luacheck.format"] = "src/luacheck/format.lua",
["luacheck.version"] = "src/luacheck/version.lua",
["luacheck.fs"] = "src/luacheck/fs.lua",
["luacheck.globber"] = "src/luacheck/globber.lua",
["luacheck.globbing"] = "src/luacheck/globbing.lua",
["luacheck.utils"] = "src/luacheck/utils.lua",
["luacheck.argparse"] = "src/luacheck/argparse.lua"
},
Expand Down
26 changes: 6 additions & 20 deletions src/luacheck/globber.lua → src/luacheck/globbing.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@ local utils = require "luacheck.utils"
-- Only ?, *, ** and simple character classes (with ranges and negation) are supported.
-- Hidden files are not treated specially. Special characters can't be escaped.
-- In ranges, - can't be used literally.
local Globber = utils.class()
local globbing = {}

function Globber:__init()
self.cur_dir = fs.current_dir()
self.cache = {}
end
local cur_dir = fs.current_dir()

local function is_regular_path(glob)
return not glob:find("[*?%[]")
Expand Down Expand Up @@ -93,9 +90,9 @@ local function parts_match(glob_parts, glob_i, path_parts, path_i)
end

-- Checks if a path matches a globbing pattern.
function Globber:match(glob, path)
glob = fs.normalize(fs.join(self.cur_dir, glob))
path = fs.normalize(fs.join(self.cur_dir, path))
function globbing.match(glob, path)
glob = fs.normalize(fs.join(cur_dir, glob))
path = fs.normalize(fs.join(cur_dir, path))

if is_regular_path(glob) then
return fs.is_subpath(glob, path)
Expand All @@ -114,15 +111,4 @@ function Globber:match(glob, path)
return parts_match(glob_parts, 1, path_parts, 1)
end

-- Returns array of all paths matching a globbing pattern.
function Globber:find(glob) -- luacheck: no self
glob = fs.normalize(glob)

if is_regular_path(glob) then
return {glob}
end

-- TODO
end

return Globber
return globbing
6 changes: 2 additions & 4 deletions src/luacheck/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ local cache = require "luacheck.cache"
local format = require "luacheck.format"
local version = require "luacheck.version"
local fs = require "luacheck.fs"
local Globber = require "luacheck.globber"
local globbing = require "luacheck.globbing"
local utils = require "luacheck.utils"

local function critical(msg)
Expand Down Expand Up @@ -159,11 +159,9 @@ Otherwise, the pattern matches warning code.]])
return parser
end

local globber = Globber()

local function match_any(globs, name)
for _, glob in ipairs(globs) do
if globber:match(glob, name) then
if globbing.match(glob, name) then
return true
end
end
Expand Down

0 comments on commit c968312

Please sign in to comment.