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

Internal Tool: ale#util#MapMatches #3632

Closed
w0rp opened this issue Mar 15, 2021 · 0 comments
Closed

Internal Tool: ale#util#MapMatches #3632

w0rp opened this issue Mar 15, 2021 · 0 comments
Assignees

Comments

@w0rp
Copy link
Member

w0rp commented Mar 15, 2021

ALE has had ale#util#GetMatches for internal use a while, and has also only supported versions of NeoVim that have lambdas for a while. I realised that we can add another function ale#util#MapMatches for making it even easier to write some helper functions, which will accept a function for mapping matches to loclist items.

Take my recent systemd-analyze linter as an example:

function! ale_linters#systemd#systemd_analyze#Handle(buffer, lines) abort
    let l:re = '\v(.+):([0-9]+): (.+)'
    let l:output = []

    for l:match in ale#util#GetMatches(a:lines, l:re)
        call add(l:output, {
        \   'lnum': str2nr(l:match[2]),
        \   'col': 1,
        \   'type': 'W',
        \   'text': l:match[3],
        \})
    endfor

    return l:output
endfunction

call ale#linter#Define('systemd', {
\   'name': 'systemd_analyze',
\   'aliases': ['systemd-analyze'],
\   'executable': 'systemd-analyze',
\   'command': 'SYSTEMD_LOG_COLOR=0 %e --user verify %s',
\   'callback': 'ale_linters#systemd#systemd_analyze#Handle',
\   'output_stream': 'both',
\   'lint_file': 1,
\})

With the new function, it can be shortened down to the following:

call ale#linter#Define('systemd', {
\   'name': 'systemd_analyze',
\   'aliases': ['systemd-analyze'],
\   'executable': 'systemd-analyze',
\   'command': 'SYSTEMD_LOG_COLOR=0 %e --user verify %s',
\   'callback': {buffer, lines -> ale#util#MapMatches(
\       lines, 
\       '\v(.+):([0-9]+): (.+)', 
\       {match -> {
\           'lnum': str2nr(match[2]),
\           'col': 1,
\           'type': 'W',
\           'text': match[3],
\       }}
\   )},
\   'output_stream': 'both',
\   'lint_file': 1,
\})
@w0rp w0rp self-assigned this Mar 15, 2021
w0rp added a commit that referenced this issue Mar 15, 2021
@w0rp w0rp closed this as completed Mar 15, 2021
jsit added a commit to jsit/ale that referenced this issue Mar 30, 2021
* master: (214 commits)
  improve DMD handler (dense-analysis#3647)
  Add support for V: "v" (compiler) and "vfmt" fixer. (dense-analysis#3622)
  Add nixfmt as a Nix fixer. (dense-analysis#3651)
  Switch to using buildifier's -path option (dense-analysis#3640)
  Add support for `ptop` fixer (dense-analysis#3652)
  Add more parameters to the DMD linting command (dense-analysis#3639)
  dense-analysis#3633 - Move linter tests into test/linter
  Allow more time before PRs become stale
  Add support for clangd with CUDA (dense-analysis#3598)
  add support for svelte via svelteserver language server (dense-analysis#3644)
  dense-analysis#3633 - Put all dummy test files in test/test-files
  Add desktop-file-validate
  Fix a typo in a test filename
  issue 3033 (dense-analysis#3620)
  dense-analysis#3632 Add ale#util#MapMatches
  Fix ale#path#Dirname on Windows
  Disable blank issues and add a link to ask for help
  Check user systemd unit files with systemd-analyze
  Close dense-analysis#2102 - Add support for the Angular language server
  Fix texlab#GetProjectRoot (dense-analysis#3610)
  ...
jsit added a commit to jsit/ale that referenced this issue Apr 19, 2021
* origin/master: (219 commits)
  Updated `solhint` linter to be able to use a local installation (dense-analysis#3682)
  Don't exit visual mode on floating preview close (dense-analysis#3689)
  hadolint: fix color output and stdin shown as "-" (dense-analysis#3680)
  feat: Add protolint as linter and fixer (dense-analysis#2911)
  apple-swift-format: linter and fixer with config swiftpm support (dense-analysis#3671)
  improve DMD handler (dense-analysis#3647)
  Add support for V: "v" (compiler) and "vfmt" fixer. (dense-analysis#3622)
  Add nixfmt as a Nix fixer. (dense-analysis#3651)
  Switch to using buildifier's -path option (dense-analysis#3640)
  Add support for `ptop` fixer (dense-analysis#3652)
  Add more parameters to the DMD linting command (dense-analysis#3639)
  dense-analysis#3633 - Move linter tests into test/linter
  Allow more time before PRs become stale
  Add support for clangd with CUDA (dense-analysis#3598)
  add support for svelte via svelteserver language server (dense-analysis#3644)
  dense-analysis#3633 - Put all dummy test files in test/test-files
  Add desktop-file-validate
  Fix a typo in a test filename
  issue 3033 (dense-analysis#3620)
  dense-analysis#3632 Add ale#util#MapMatches
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant