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

Commit

Permalink
Merge pull request #18 from AtomLinter/arcanemagus/es2017-rewrite
Browse files Browse the repository at this point in the history
Rewrite in ES2017
  • Loading branch information
Arcanemagus authored Mar 15, 2017
2 parents 03c1d26 + b853970 commit 2b9d384
Show file tree
Hide file tree
Showing 23 changed files with 301 additions and 88 deletions.
20 changes: 20 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org

root = true

[*]

# Change these settings to your own preference
indent_style = space
indent_size = 2

# We recommend you to keep these unchanged
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text eol=lf
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
# linter-flint
Lint projects using `flint`

You can find flint [here](https://github.com/pengwynn/flint).
Lint projects using [`flint`][flint].

# Installation

You need to have [`flint`][flint] installed on your system before using this
package. Once that is setup this package should work right away. If you are
getting messages about `flint` not being available you may need to set the full
path to it in your settings.

As this package is just a wrapper around `flint`, you will need something to
actually run it. By default the [Linter][] package will be installed for you to
fill this need.


[flint]: https://github.com/pengwynn/flint
[Linter]: https://atom.io/packages/linter
39 changes: 0 additions & 39 deletions lib/linter-flint.coffee

This file was deleted.

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

// eslint-disable-next-line import/no-extraneous-dependencies, import/extensions
import { CompositeDisposable } from 'atom';
import { exec } from 'atom-linter';
import { dirname } from 'path';
import escapeHTML from 'escape-html';

// Internal vars
// Example: https://regex101.com/r/OfS9w0/2/
const regex = /\[([A-Z]+)\] (.+)(?:\n\[INFO\] ([^\n.]+.)(?: (http:.+))?\n?)?/gm;

export default {
activate() {
require('atom-package-deps').install('linter-flint');

this.subscriptions = new CompositeDisposable();

this.subscriptions.add(
atom.config.observe('linter-flint.executablePath', (value) => {
this.executablePath = value;
}),
);
this.subscriptions.add(
atom.config.observe('linter-flint.skipReadme', (value) => {
this.skipReadme = value;
}),
);
this.subscriptions.add(
atom.config.observe('linter-flint.skipContributing', (value) => {
this.skipContributing = value;
}),
);
this.subscriptions.add(
atom.config.observe('linter-flint.skipLicense', (value) => {
this.skipLicense = value;
}),
);
this.subscriptions.add(
atom.config.observe('linter-flint.skipBootstrap', (value) => {
this.skipBootstrap = value;
}),
);
this.subscriptions.add(
atom.config.observe('linter-flint.skipTestScript', (value) => {
this.skipTestScript = value;
}),
);
this.subscriptions.add(
atom.config.observe('linter-flint.skipScripts', (value) => {
this.skipScripts = value;
}),
);
},

deactivate() {
this.subscriptions.dispose();
},

provideLinter() {
return {
name: 'Flint',
grammarScopes: ['*'],
scope: 'project',
lintOnFly: false,
lint: async (editor) => {
const filePath = editor.getPath();
let projectPath = atom.project.relativizePath(filePath)[0];
if (projectPath === null) {
projectPath = dirname(filePath);
}

const execArgs = ['--no-color'];
if (this.skipReadme) {
execArgs.push('--skip-readme');
}
if (this.skipContributing) {
execArgs.push('--skip-contributing');
}
if (this.skipLicense) {
execArgs.push('--skip-license');
}
if (this.skipBootstrap) {
execArgs.push('--skip-bootstrap');
}
if (this.skipTestScript) {
execArgs.push('--skip-test-script');
}
if (this.skipScripts) {
execArgs.push('--skip-scripts');
}

const execOpts = {
cwd: projectPath,
stream: 'stderr',
};

const output = await exec(this.executablePath, execArgs, execOpts);

const toReturn = [];

let match = regex.exec(output);
while (match !== null) {
const [type, text, info, url] = match.slice(1);
if (type !== 'OK') {
const message = {
type: type === 'WARNING' ? 'Warning' : 'Error',
severity: type === 'WARNING' ? 'warning' : 'error',
text,
};
if (info) {
const trace = {
type: 'Trace',
severity: 'info',
};
if (url) {
trace.html = `${escapeHTML(info)} (<a href="${url}">link</a>)`;
} else {
trace.text = info;
}
message.trace = [trace];
}
toReturn.push(message);
}
match = regex.exec(output);
}
return toReturn;
},
};
},
};
44 changes: 0 additions & 44 deletions lib/provider.coffee

This file was deleted.

63 changes: 60 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,42 @@
{
"name": "linter-flint",
"main": "./lib/linter-flint",
"main": "./lib/linter-flint.js",
"version": "0.1.2",
"description": "Lint projects using flint",
"repository": "https://github.com/AtomLinter/linter-flint",
"license": "MIT",
"engines": {
"atom": ">0.50.0"
"atom": ">=1.4.0 <2.0.0"
},
"configSchema": {
"executablePath": {
"type": "string",
"default": "flint"
},
"skipReadme": {
"type": "boolean",
"default": false
},
"skipContributing": {
"type": "boolean",
"default": false
},
"skipLicense": {
"type": "boolean",
"default": false
},
"skipBootstrap": {
"type": "boolean",
"default": false
},
"skipTestScript": {
"type": "boolean",
"default": false
},
"skipScripts": {
"type": "boolean",
"default": false
}
},
"providedServices": {
"linter": {
Expand All @@ -16,7 +46,34 @@
}
},
"dependencies": {
"atom-package-deps": "^4.0.1"
"atom-linter": "^9.0.1",
"atom-package-deps": "^4.0.1",
"escape-html": "^1.0.3"
},
"devDependencies": {
"eslint": "^3.16.1",
"eslint-config-airbnb-base": "^11.1.1",
"eslint-plugin-import": "^2.2.0"
},
"eslintConfig": {
"extends": "airbnb-base",
"rules": {
"global-require": "off",
"import/no-unresolved": [
"error",
{
"ignore": [
"atom"
]
}
]
},
"globals": {
"atom": true
},
"env": {
"node": true
}
},
"package-deps": [
"linter"
Expand Down
6 changes: 6 additions & 0 deletions spec/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
env: {
atomtest: true,
jasmine: true
}
};
Empty file.
Empty file.
Empty file.
Empty file.
Empty file added spec/fixtures/badProj/README.md
Empty file.
3 changes: 3 additions & 0 deletions spec/fixtures/badProj/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "invalid project"
}
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
3 changes: 3 additions & 0 deletions spec/fixtures/goodProj/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "invalid project"
}
Empty file.
Empty file.
Loading

0 comments on commit 2b9d384

Please sign in to comment.