Skip to content

Commit

Permalink
Merge pull request #98 from AtomLinter/steelbrain/use-named-js-regexp
Browse files Browse the repository at this point in the history
Use named-js-regexp instead of xregexp
  • Loading branch information
steelbrain committed Jan 20, 2016
2 parents d6f6ff1 + 5fbdf8e commit 09e8f4c
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 26 deletions.
52 changes: 38 additions & 14 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var _consistentPath = require('consistent-path');

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }

let XRegExp = null;
let NamedRegexp = null;
const FindCache = exports.FindCache = new Map();

// TODO: Remove this when electron upgrades node
Expand Down Expand Up @@ -246,14 +246,36 @@ function find(directory, name) {
if (currentDir === '') {
currentDir = Path.resolve(directory, '/');
}
for (const fileName of names) {
const filePath = Path.join(currentDir, fileName);
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;

try {
for (var _iterator = names[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
const fileName = _step.value;

const filePath = Path.join(currentDir, fileName);

try {
FS.accessSync(filePath, FS.R_OK);
return filePath;
} catch (_) {}
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
FS.accessSync(filePath, FS.R_OK);
return filePath;
} catch (_) {}
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}

chunks.pop();
}

Expand Down Expand Up @@ -361,17 +383,19 @@ function parse(data, regex) {
throw new Error('Invalid or no `options` provided');
}

if (XRegExp === null) {
XRegExp = require('xregexp').XRegExp;
if (NamedRegexp === null) {
NamedRegexp = require('named-js-regexp');
}

const options = assign({ flags: '' }, opts);
options.flags += 'g';

const messages = [];
const options = assign({
flags: 'g'
}, opts);
const xregex = XRegExp(regex, options.flags);
const compiledRegexp = NamedRegexp(regex, options.flags);
let rawMatch = null;

XRegExp.forEach(data, xregex, function (match) {
while ((rawMatch = compiledRegexp.exec(data)) !== null) {
const match = rawMatch.groups();
const type = match.type;
const text = match.message;
const file = match.file || options.filePath || null;
Expand All @@ -387,7 +411,7 @@ function parse(data, regex) {
filePath: file,
range: [[lineStart > 0 ? lineStart - 1 : 0, colStart > 0 ? colStart - 1 : 0], [lineEnd > 0 ? lineEnd - 1 : 0, colEnd > 0 ? colEnd - 1 : 0]]
});
});
}

return messages;
}
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
},
"homepage": "https://github.com/AtomLinter/atom-linter#readme",
"dependencies": {
"xregexp": "^3.0.0",
"tmp": "latest",
"consistent-path": "^1.0.3"
"consistent-path": "^1.0.3",
"named-js-regexp": "^1.3.1",
"tmp": "latest"
},
"devDependencies": {
"babel-preset-steelbrain": "^1.0.0"
Expand Down
20 changes: 11 additions & 9 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as FS from 'fs'
import * as TMP from 'tmp'
import {getPath} from 'consistent-path'

let XRegExp = null
let NamedRegexp = null
export const FindCache = new Map()

// TODO: Remove this when electron upgrades node
Expand Down Expand Up @@ -327,17 +327,19 @@ export function parse(data, regex, opts = {}) {
throw new Error('Invalid or no `options` provided')
}

if (XRegExp === null) {
XRegExp = require('xregexp').XRegExp
if (NamedRegexp === null) {
NamedRegexp = require('named-js-regexp')
}

const options = assign({flags: ''}, opts)
options.flags += 'g'

const messages = []
const options = assign({
flags: 'g'
}, opts)
const xregex = XRegExp(regex, options.flags)
const compiledRegexp = NamedRegexp(regex, options.flags)
let rawMatch = null

XRegExp.forEach(data, xregex, function(match) {
while ((rawMatch = compiledRegexp.exec(data)) !== null) {
const match = rawMatch.groups()
const type = match.type
const text = match.message
const file = match.file || options.filePath || null
Expand All @@ -356,7 +358,7 @@ export function parse(data, regex, opts = {}) {
[lineEnd > 0 ? lineEnd - 1 : 0, colEnd > 0 ? colEnd - 1 : 0],
]
})
})
}

return messages
}

0 comments on commit 09e8f4c

Please sign in to comment.