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

Decaffeinate and maintenance #20

Merged
merged 7 commits into from
Jan 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
27 changes: 20 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
### Project specific config ###
language: generic
language: node_js
node_js:
- "8"

env:
global:
- secure: "ixSEYjGpVSOPGu0t58ZWOZ/FudTrOa1vkV5MxHdkRMyDi2S25naE7cQukxaFwQk/Mn1bk+LJl6cyDT6wrd8BeNdWVOTy/+ZZB2mMa5oYGN1eGFG+p9JAshCLjfNmPj6gz6Ubo5iuKXkBjckvCFj2DQgvgBHRn2mP3+coGLn/9rfChSU0VbyTSx0gHp7+G4VOvs9sgG5tkxLuc1ItHJuDoeZlGW4R660LqY+HDRZRFBcJft2+zPMWOGbOMEMHnNBSOfyfaeAeHulJRd8TJ05/IAyGsoU8biXFxCAjveSSMT6IWAOkBdpaDVacDg0P7ClYvxup0eAImHlOXaoSaMUWLu4pvSk+6FTG2qauRT+t0igeWNuNdu5X4kmdL50vDvykLW88ln1pJ8hflEeH7sV8aTvStklXgSoi5PaCtpKLlDp3HXw9tTgV7iC+afVm2gpJUL7RB7yAInptUci+Bnq7FqVpGXUFlLbIP4VbB8sApI0ZaarbpQVMsP6N3N8pHtOEPMu0PepRIbqnf/cnRKxe1GdI0VU2JTMYgHq+OqFou4EuQKtNW+6552TiXY8Johl3vdJQWCbby88YfPkx1hRETAoVA/fUpkeO3lo4A0PIFzdQeG+8ZyOG4Seg3kvA9Lc8d3L5yEQtdVJR0vWWds7Va++NP1O3bx3eTGBQcBqN+K4="
- secure: "VWt+R8fkwoezX+5WdB5Bmb09fIGvOCcwxdYhxdkMQlpWbPwlZoqw3OYY/9/aLGIAEzpYxSpKWvA+McMRmvmzQWRknWmhwwt2+MbQkfpy9k8rpoJmGQsBEWmcC7aQ/38fyDUgx5vxWuADyCVa0dzm6MqgL3E9VlhJaNCnJfsA+oadN6EG5S5sYRTQdBiarZ+GEqzcS50Nii/HuHUT881EXKPcMkSuefyzpzmEbVzwwECG2Huq1po0KErY1Ud4QgQyyI8JG/JaXIoAKloACfkL+oMbInfi0/4/hL4kOUWOOglNc1hwn+C1bTwsndyTaqgAdbIzLbid7acww/Mb0dufCnf4ddF1fQTCYNuaGLe/WuqszQHUMn1/2uxE9hjJY/Q0pAPXmsjV/ju3nEvRNZ6t2ABYSiXkN09Ro6R7DohR18Pdcj5b1Vb0kh8jDg/ljd368FQMN9pvw3Gj7qi3AEAyyDqLgdvm6ikyuQKiOgqwDwsbSCqgBAYZJgRQnCf7h2Wah1zY7djIBG+01mtLbPpcOh3D2mxSg0wmg4E9wMpJwYxsmHy5YvP+wTKinQWk1oPRgUtgEK4Z0m1mHsilcS0dZDDyLf6UxzCqvma/r7eJUV1XrsfSypen1yCyWYdT2SrB7m6tyXp4PjN2htKpemjiY57yHQxSOWWglDDeK6i7xy0="
matrix:
- ATOM_CHANNEL=stable
- ATOM_CHANNEL=beta

os:
- linux

### Generic setup follows ###
dist: trusty
before_script:
- commitlint-travis

after_success:
# Add apm to the PATH
- export PATH=${PATH}:${HOME}/atom/usr/bin/
- npm run travis-deploy-once "npm run semantic-release"

### Generic setup follows ###
script:
- curl -s -O https://raw.githubusercontent.com/atom/ci/master/build-package.sh
- chmod u+x build-package.sh
- ./build-package.sh
- "./build-package.sh"

notifications:
email:
Expand All @@ -25,17 +36,19 @@ notifications:
branches:
only:
- master
- /^greenkeeper/.*$/
- "/^greenkeeper/.*$/"

git:
depth: 10

sudo: false

dist: trusty

addons:
apt:
packages:
- build-essential
- git
- libgnome-keyring-dev
- fakeroot
- git
- libsecret-1-dev
5 changes: 5 additions & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
extends: [
'@commitlint/config-conventional',
],
};
122 changes: 0 additions & 122 deletions lib/init.coffee

This file was deleted.

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

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

// Dependencies
let bundledPugLint;
let objectAssign;
let configFile;
let helpers;
let resolve;

const pugLints = new Map();

const resolvePath = (name, basedir) =>
new Promise(((res, reject) =>
resolve(name, { basedir }, (err, modulePath) => {
if (err != null) {
reject(err);
}
return res(modulePath);
})
));

const getPugLint = async (baseDir) => {
if (pugLints.has(baseDir)) {
return pugLints.get(baseDir);
}

try {
const pugLintPath = await resolvePath('pug-lint', baseDir);
// eslint-disable-next-line import/no-dynamic-require
pugLints.set(baseDir, require(pugLintPath));
} catch (e) {
pugLints.set(baseDir, bundledPugLint);
}

return pugLints.get(baseDir);
};

const loadDeps = () => {
if (!bundledPugLint) {
bundledPugLint = require('pug-lint');
}
if (!objectAssign) {
objectAssign = require('object-assign');
}
if (!configFile) {
configFile = require('pug-lint/lib/config-file');
}
if (!helpers) {
helpers = require('atom-linter');
}
if (!resolve) {
resolve = require('resolve');
}
};

module.exports = {
activate() {
this.idleCallbacks = new Set();
let depsCallbackID;
const installLinterJSHintDeps = () => {
this.idleCallbacks.delete(depsCallbackID);
loadDeps();
};
depsCallbackID = window.requestIdleCallback(installLinterJSHintDeps);
this.idleCallbacks.add(depsCallbackID);

if (atom.config.get('linter-pug.executablePath')) {
atom.notifications.addWarning(
'Removing custom pug-lint path',
{
detail: 'linter-pug has moved to the Node.js API for pug-lint and ' +
"will now use a project's local instance where possible, falling " +
'back to a bundled version of pug-lint if none is found.',
},
);
atom.config.unset('linter-pug.executablePath');
}

this.subscriptions = new CompositeDisposable();
this.subscriptions.add(atom.config.observe(
'linter-pug.projectConfigFile',
(value) => { this.projectConfigFile = value; },
));
this.subscriptions.add(atom.config.observe(
'linter-pug.onlyRunWhenConfig',
(value) => { this.onlyRunWhenConfig = value; },
));
},

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

getConfig(filePath) {
let config;
if (path.isAbsolute(this.projectConfigFile)) {
config = configFile.load(false, this.projectConfigFile);
} else {
config = configFile.load(false, path.join(path.dirname(filePath), this.projectConfigFile));
}
if (!config && this.onlyRunWhenConfig) {
return undefined;
}

const options = {};
const newConfig = objectAssign(options, config);

if (!newConfig.configPath && config && config.configPath) {
newConfig.configPath = config.configPath;
}
return newConfig;
},

provideLinter() {
return {
name: 'pug-lint',
grammarScopes: ['source.jade', 'source.pug'],
scope: 'file',
lintOnFly: true,

lint: async (textEditor) => {
if (!atom.workspace.isTextEditor(textEditor)) {
// Somehow, called with an invalid TextEditor instance
return null;
}

const filePath = textEditor.getPath();
if (!filePath) {
// File somehow has no path
return null;
}

const fileText = textEditor.getText();
if (!fileText) {
// Nothing in the file
return null;
}

// Load the dependencies if they aren't already
loadDeps();

const projectConfig = this.getConfig(filePath);
if (!projectConfig || !projectConfig.configPath) {
if (this.onlyRunWhenConfig) {
atom.notifications.addError('Pug-lint config not found');
return null;
}
}

let rules = [];
if (this.onlyRunWhenConfig || projectConfig) {
rules = projectConfig;
}

// Use Atom's project root folder
let projectDir = atom.project.relativizePath(filePath)[0];
if ((projectDir == null)) {
// Fall back to the file directory
projectDir = path.dirname(filePath);
}

const linter = new (await getPugLint(projectDir))();
linter.configure(rules);
const results = linter.checkString(fileText, filePath);
return results.map(res => ({
severity: 'error',
location: {
file: res.filename,
position: helpers.generateRange(textEditor, res.line - 1, res.column - 1),
},
excerpt: res.msg,
}));
},
};
},
};
Loading