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

V2 linter API support #12

Merged
merged 27 commits into from
Feb 14, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
316f1e7
V2 linter API support
vzamanillo Feb 13, 2019
653ebb4
Force deprecation warning in fixture file
vzamanillo Feb 13, 2019
c83a5d8
Fixed TypeError: Cannot read property 'length' of null
vzamanillo Feb 13, 2019
0ab6678
Added CI configuration
vzamanillo Feb 13, 2019
7e92713
Added Travis CI config file
vzamanillo Feb 13, 2019
a60007c
Version number changes are always done during the release process.
vzamanillo Feb 13, 2019
2f0ca69
Override title for executable path
vzamanillo Feb 13, 2019
d64bfc6
Updated settings doc to avoid manual configuration using the config.cson
vzamanillo Feb 13, 2019
454aac7
Typo
vzamanillo Feb 13, 2019
368542e
Avoid escape characters
vzamanillo Feb 13, 2019
faa4b0b
It must "be"
vzamanillo Feb 13, 2019
9612f7a
Uneeded step, no sources to compile (bad ctrl+c - ctrl+v :/)
vzamanillo Feb 13, 2019
1314467
We are installing slim deps...
vzamanillo Feb 13, 2019
8dc3f4d
Atom's configuration schema ensures the result will always be an Array.
vzamanillo Feb 13, 2019
7305b42
Atom linter named as linter repo.
vzamanillo Feb 13, 2019
fccc499
If we somehow get fed an invalid TextEditor just immediately return
vzamanillo Feb 13, 2019
76e7438
Added dep lock file
vzamanillo Feb 13, 2019
d6b6e10
Merge branch 'master'
vzamanillo Feb 13, 2019
b396b9c
Capitalized executable
vzamanillo Feb 13, 2019
0cbdd22
Uneeded branches
vzamanillo Feb 13, 2019
a8926eb
Quoted "./build-package.sh"
vzamanillo Feb 13, 2019
c77a723
Recovered branches without greenkeeper
vzamanillo Feb 13, 2019
5118d4d
Needed packages for test env
vzamanillo Feb 13, 2019
4f93476
Needed packages for test env on Travis
vzamanillo Feb 14, 2019
4899a97
Global env
vzamanillo Feb 14, 2019
5717a16
Step to install slim
vzamanillo Feb 14, 2019
422e6b8
Install ruby before install Slim
vzamanillo Feb 14, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
version: 2

defaults: &defaults
working_directory: /tmp/project
docker:
- image: arcanemagus/atom-docker-ci:stable
steps:
# Restore project state
- attach_workspace:
at: /tmp
- run:
name: Create VFB for Atom to run in
command: /usr/local/bin/xvfb_start
- run:
name: Atom version
command: ${ATOM_SCRIPT_PATH} --version
- run:
name: APM version
command: ${APM_SCRIPT_PATH} --version
- run:
name: Package APM package dependencies
command: |
if [ -n "${APM_TEST_PACKAGES}" ]; then
for pack in ${APM_TEST_PACKAGES}; do
${APM_SCRIPT_PATH} install "${pack}"
done
fi;
- run:
name: Package dependencies
command: ${APM_SCRIPT_PATH} install
- run:
name: Cleaning package
command: ${APM_SCRIPT_PATH} clean
- run:
name: Package specs
command: ${ATOM_SCRIPT_PATH} --test spec
# Cache node_modules
- save_cache:
paths:
- node_modules
key: v1-dependencies-{{ .Branch }}-{{ checksum "package.json" }}-{{ checksum "package-lock.json"}}

jobs:
checkout_code:
<<: *defaults
docker:
- image: circleci/node:latest
steps:
- checkout
# Restore node_modules from the last build
- restore_cache:
keys:
# Get latest cache for this package.json and package-lock.json
- v1-dependencies-{{ .Branch }}-{{ checksum "package.json" }}-{{ checksum "package-lock.json"}}
# Fallback to the current package.json
- v1-dependencies-{{ .Branch }}-{{ checksum "package.json" }}-
# Fallback to the last build for this branch
- v1-dependencies-{{ .Branch }}-
# Fallback to the last available master branch cache
- v1-dependencies-master-
# Don't go further down to prevent dependency issues from other branches
# Save project state for next steps
- persist_to_workspace:
root: /tmp
paths:
- project
lint:
<<: *defaults
docker:
- image: circleci/node:lts
steps:
# Restore project state
- attach_workspace:
at: /tmp
- run:
name: Node.js Version
command: node --version
- run:
name: NPM Version
command: npm --version
- run:
name: Install any remaining dependencies
command: npm install
- run:
name: Compile sources
command: npm run compile
Arcanemagus marked this conversation as resolved.
Show resolved Hide resolved
- run:
name: Lint code
command: npm run lint
stable:
<<: *defaults
beta:
<<: *defaults
docker:
- image: arcanemagus/atom-docker-ci:beta

workflows:
version: 2
test_package:
jobs:
- checkout_code
- lint:
requires:
- checkout_code
- stable:
requires:
- lint
- beta:
requires:
- lint
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ You can configure linter-slim by editing ~/.atom/config.cson (choose Open Your C

```
Arcanemagus marked this conversation as resolved.
Show resolved Hide resolved
'linter-slim':
'executableDir': null # slimrb directory path.
'binaryName': slimrb # slimrb binary name.
'slimrbExecutablePath': slimrb # slimrb executable path.
'rails': true # generates rails compatible code.
'library': [] # load library or plugin (e.g. slim/plugin).
```
Expand Down
23 changes: 0 additions & 23 deletions lib/init.coffee

This file was deleted.

65 changes: 0 additions & 65 deletions lib/linter-slim.coffee

This file was deleted.

136 changes: 136 additions & 0 deletions lib/linter-slim.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
'use babel';

// eslint-disable-next-line import/no-extraneous-dependencies, import/extensions
import { CompositeDisposable } from 'atom';

let helpers;

// Deprecated syntax:
const REGEX = /.*(SyntaxError|Deprecated).*: (.+)\n.+, Line (\d+), Column (\d+)/g;

const severityMapping = {
deprecated: 'warning',
syntaxerror: 'error',
};

const loadDeps = () => {
if (!helpers) {
helpers = require('atom-linter');
}
};

const parseCompileOutput = (output, filePath, editor) => {
const messages = [];

let match = REGEX.exec(output);
while (match !== null) {
const severity = severityMapping[match[1].toLowerCase()] || 'warning';
const line = Number.parseInt(match[3], 10) - 1;
const col = Number.parseInt(match[4], 10) - 1;
const excerpt = `${match[1]}: ${match[2]}`;
messages.push({
severity,
excerpt,
location: {
file: filePath,
position: helpers.generateRange(editor, line, col),
},
});
match = REGEX.exec(output);
}
return messages;
};

module.exports = {
activate() {
this.idleCallbacks = new Set();
let depsCallbackID;
const installLinterReekDeps = () => {
Arcanemagus marked this conversation as resolved.
Show resolved Hide resolved
this.idleCallbacks.delete(depsCallbackID);
if (!atom.inSpecMode()) {
require('atom-package-deps').install('linter-slim');
}
loadDeps();
};
depsCallbackID = window.requestIdleCallback(installLinterReekDeps);
Arcanemagus marked this conversation as resolved.
Show resolved Hide resolved
this.idleCallbacks.add(depsCallbackID);

this.subscriptions = new CompositeDisposable();
this.subscriptions.add(
atom.config.observe(
'linter-slim.slimrbExecutablePath',
(value) => { this.slimrbExecutablePath = value; },
),
atom.config.observe(
'linter-slim.rails',
(value) => { this.rails = value; },
),
atom.config.observe(
'linter-slim.library',
(value) => { this.library = value; },
),
);
},

deactivate() {
this.idleCallbacks.forEach(callbackID => window.cancelIdleCallback(callbackID));
this.idleCallbacks.clear();
this.subscriptions.dispose();
},

provideLinter() {
return {
name: 'slimrb',
Arcanemagus marked this conversation as resolved.
Show resolved Hide resolved
grammarScopes: ['text.slim'],
scope: 'file',
lintsOnChange: true,
lint: async (editor) => {
loadDeps();

Arcanemagus marked this conversation as resolved.
Show resolved Hide resolved
const filePath = editor.getPath();
if (!filePath) {
return null;
}

const args = [];
args.push('--compile');

if (this.rails) {
args.push('--rails');
}

if (Array.isArray(this.library) && this.library.length) {
Arcanemagus marked this conversation as resolved.
Show resolved Hide resolved
args.push('--require', this.library.join(' '));
}

args.push(filePath);

const execOptions = {
stream: 'stderr',
uniqueKey: `linter-slim::${filePath}`,
allowEmptyStderr: true,
};

let output;
try {
output = await helpers.exec(this.slimrbExecutablePath, args, execOptions);
} catch (e) {
if (e.message === 'Process execution timed out') {
atom.notifications.addInfo('linter-slim: `slimrb` timed out', {
description: 'A timeout occured while executing `slimrb`, it could be due to lower resources '
+ 'or a temporary overload.',
});
} else {
atom.notifications.addError('linter-slimrb: Unexpected error', { description: e.message });
}
return null;
}

// Process was canceled by newer process
if (output === null) { return null; }

return parseCompileOutput(output, filePath, editor);
},
};
},
};
Loading