Skip to content
This repository was archived by the owner on Aug 7, 2023. It is now read-only.

Commit 59f6c31

Browse files
authored
Merge pull request #54 from vzamanillo/v2-linter-api-support
V2 linter API support
2 parents 45e33d2 + 6caf897 commit 59f6c31

File tree

10 files changed

+1878
-52
lines changed

10 files changed

+1878
-52
lines changed

.circleci/config.yml

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
version: 2
2+
3+
defaults: &defaults
4+
working_directory: /tmp/project
5+
environment:
6+
APM_TEST_PACKAGES: "language-lua"
7+
docker:
8+
- image: arcanemagus/atom-docker-ci:stable
9+
steps:
10+
# Restore project state
11+
- attach_workspace:
12+
at: /tmp
13+
- run:
14+
name: Install luac and luajit
15+
command: |
16+
sudo apt-get update && \
17+
sudo apt-get install --assume-yes --quiet --no-install-suggests \
18+
--no-install-recommends lua5.3 luajit && \
19+
sudo update-alternatives --install /usr/bin/lua lua-interpreter \
20+
/usr/bin/lua5.3 130 --slave /usr/share/man/man1/lua.1.gz lua-manual /usr/share/man/man1/lua5.3.1.gz && \
21+
sudo update-alternatives --install /usr/bin/luac lua-compiler \
22+
/usr/bin/luac5.3 130 --slave /usr/share/man/man1/luac.1.gz lua-compiler-manual /usr/share/man/man1/luac5.3.1.gz
23+
- run:
24+
name: Luac version
25+
command: luac -v
26+
- run:
27+
name: Luajit version
28+
command: luajit -v
29+
- run:
30+
name: Create VFB for Atom to run in
31+
command: /usr/local/bin/xvfb_start
32+
- run:
33+
name: Atom version
34+
command: ${ATOM_SCRIPT_PATH} --version
35+
- run:
36+
name: APM version
37+
command: ${APM_SCRIPT_PATH} --version
38+
- run:
39+
name: Package APM package dependencies
40+
command: |
41+
if [ -n "${APM_TEST_PACKAGES}" ]; then
42+
for pack in ${APM_TEST_PACKAGES}; do
43+
${APM_SCRIPT_PATH} install "${pack}"
44+
done
45+
fi;
46+
- run:
47+
name: Package dependencies
48+
command: ${APM_SCRIPT_PATH} install
49+
- run:
50+
name: Cleaning package
51+
command: ${APM_SCRIPT_PATH} clean
52+
- run:
53+
name: Package specs
54+
command: ${ATOM_SCRIPT_PATH} --test spec
55+
# Cache node_modules
56+
- save_cache:
57+
paths:
58+
- node_modules
59+
key: v1-dependencies-{{ .Branch }}-{{ checksum "package.json" }}-{{ checksum "package-lock.json"}}
60+
61+
jobs:
62+
checkout_code:
63+
<<: *defaults
64+
docker:
65+
- image: circleci/node:latest
66+
steps:
67+
- checkout
68+
# Restore node_modules from the last build
69+
- restore_cache:
70+
keys:
71+
# Get latest cache for this package.json and package-lock.json
72+
- v1-dependencies-{{ .Branch }}-{{ checksum "package.json" }}-{{ checksum "package-lock.json"}}
73+
# Fallback to the current package.json
74+
- v1-dependencies-{{ .Branch }}-{{ checksum "package.json" }}-
75+
# Fallback to the last build for this branch
76+
- v1-dependencies-{{ .Branch }}-
77+
# Fallback to the last available master branch cache
78+
- v1-dependencies-master-
79+
# Don't go further down to prevent dependency issues from other branches
80+
# Save project state for next steps
81+
- persist_to_workspace:
82+
root: /tmp
83+
paths:
84+
- project
85+
lint:
86+
<<: *defaults
87+
docker:
88+
- image: circleci/node:lts
89+
steps:
90+
# Restore project state
91+
- attach_workspace:
92+
at: /tmp
93+
- run:
94+
name: Node.js Version
95+
command: node --version
96+
- run:
97+
name: NPM Version
98+
command: npm --version
99+
- run:
100+
name: Install any remaining dependencies
101+
command: npm install
102+
- run:
103+
name: Lint code
104+
command: npm run lint
105+
stable:
106+
<<: *defaults
107+
beta:
108+
<<: *defaults
109+
docker:
110+
- image: arcanemagus/atom-docker-ci:beta
111+
112+
workflows:
113+
version: 2
114+
test_package:
115+
jobs:
116+
- checkout_code
117+
- lint:
118+
requires:
119+
- checkout_code
120+
- stable:
121+
requires:
122+
- lint
123+
- beta:
124+
requires:
125+
- lint

.travis.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
### Project specific config ###
2+
3+
language: generic
4+
5+
matrix:
6+
include:
7+
- os: linux
8+
env: ATOM_CHANNEL=stable
9+
10+
- os: linux
11+
env: ATOM_CHANNEL=beta
12+
13+
env:
14+
global:
15+
APM_TEST_PACKAGES: "language-lua"
16+
17+
install:
18+
- sudo apt-get update
19+
- sudo apt-get install --assume-yes --quiet --no-install-suggests --no-install-recommends lua5.2 luajit
20+
21+
before_script:
22+
- luac -v
23+
- luajit -v
24+
25+
### Generic setup follows ###
26+
script:
27+
- curl -s -O https://raw.githubusercontent.com/atom/ci/master/build-package.sh
28+
- chmod u+x build-package.sh
29+
- "./build-package.sh"
30+
31+
notifications:
32+
email:
33+
on_success: never
34+
on_failure: change
35+
36+
branches:
37+
only:
38+
- master
39+
40+
git:
41+
depth: 10
42+
43+
sudo: false
44+
45+
dist: trusty
46+
47+
addons:
48+
apt:
49+
packages:
50+
- build-essential
51+
- fakeroot
52+
- git
53+
- libsecret-1-dev

lib/init.js

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
'use babel';
2+
3+
// eslint-disable-next-line import/no-extraneous-dependencies, import/extensions
4+
import { CompositeDisposable } from 'atom';
5+
6+
let helpers;
7+
8+
const REGEX = /^.+?:.+?:(\d+):\s+(.+?(?:near (.+)|$))/g;
9+
10+
const loadDeps = () => {
11+
if (!helpers) {
12+
helpers = require('atom-linter');
13+
}
14+
};
15+
16+
const parseLuacOutput = (output, file, editor) => {
17+
const messages = [];
18+
let match = REGEX.exec(output);
19+
while (match !== null) {
20+
const line = Number.parseInt(match[1], 10) - 1;
21+
messages.push({
22+
severity: 'error',
23+
excerpt: match[2],
24+
location: {
25+
file,
26+
position: helpers.generateRange(editor, line),
27+
},
28+
});
29+
match = REGEX.exec(output);
30+
}
31+
return messages;
32+
};
33+
34+
module.exports = {
35+
activate() {
36+
this.idleCallbacks = new Set();
37+
let depsCallbackID;
38+
const installLinterLuaDeps = () => {
39+
this.idleCallbacks.delete(depsCallbackID);
40+
if (!atom.inSpecMode()) {
41+
require('atom-package-deps').install('linter-lua');
42+
}
43+
loadDeps();
44+
};
45+
depsCallbackID = window.requestIdleCallback(installLinterLuaDeps);
46+
this.idleCallbacks.add(depsCallbackID);
47+
48+
this.subscriptions = new CompositeDisposable();
49+
this.subscriptions.add(
50+
atom.config.observe(
51+
'linter-lua.executablePath',
52+
(value) => { this.executablePath = value; },
53+
),
54+
);
55+
},
56+
57+
deactivate() {
58+
this.idleCallbacks.forEach(callbackID => window.cancelIdleCallback(callbackID));
59+
this.idleCallbacks.clear();
60+
this.subscriptions.dispose();
61+
},
62+
63+
provideLinter() {
64+
return {
65+
name: 'Lua',
66+
grammarScopes: ['source.lua'],
67+
scope: 'file',
68+
lintsOnChange: true,
69+
lint: async (editor) => {
70+
if (!atom.workspace.isTextEditor(editor)) {
71+
// If we somehow get fed an invalid TextEditor just immediately return
72+
return null;
73+
}
74+
75+
const filePath = editor.getPath();
76+
if (!filePath) {
77+
return null;
78+
}
79+
80+
loadDeps();
81+
82+
const args = [];
83+
84+
if (this.executablePath.indexOf('luajit') !== -1) {
85+
args.push('-bl');
86+
} else {
87+
args.push('-p');
88+
}
89+
90+
args.push('-'); // to indicate that the input is in stdin
91+
92+
const stdin = editor.getText();
93+
94+
const execOptions = {
95+
stdin,
96+
stream: 'stderr',
97+
uniqueKey: `linter-lua::${filePath}`,
98+
allowEmptyStderr: true,
99+
};
100+
101+
let output;
102+
try {
103+
output = await helpers.exec(this.executablePath, args, execOptions);
104+
} catch (e) {
105+
if (e.message === 'Process execution timed out') {
106+
atom.notifications.addInfo(`linter-lua: ${this.executablePath} timed out`, {
107+
description: `A timeout occured while executing ${this.executablePath}, it could be due to lower resources `
108+
+ 'or a temporary overload.',
109+
});
110+
} else {
111+
atom.notifications.addError('linter-lua: Unexpected error', { description: e.message });
112+
}
113+
return null;
114+
}
115+
116+
if (editor.getText() !== stdin || output === null) {
117+
// File has changed since the lint was triggered, tell Linter not to update or
118+
// process was canceled by newer process
119+
return null;
120+
}
121+
122+
return parseLuacOutput(output, filePath, editor);
123+
},
124+
};
125+
},
126+
};

lib/main.coffee

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)