Skip to content

Commit

Permalink
Merge pull request #99 from AtomLinter/steelbrain/do-not-force-g-flag
Browse files Browse the repository at this point in the history
Do not force g flag
  • Loading branch information
steelbrain committed Jan 22, 2016
2 parents e79ac34 + 778b226 commit d78b20c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### 4.3.4

* Do not add `g` flag to regex if it already exists

### 4.3.3

* Switch to `named-js-regexp` instead of `xregexp` for `parse` method
Expand Down
4 changes: 3 additions & 1 deletion lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,9 @@ function parse(data, regex) {
}

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

const messages = [];
const compiledRegexp = NamedRegexp(regex, options.flags);
Expand Down
11 changes: 11 additions & 0 deletions spec/helper-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,17 @@ describe 'linter helpers', ->
results = helpers.parse(input, regex, {flags: "i"})
expect(results).toEqual(output)

regex = 'type:(?<type>.+) message:(?<message>.+)'
input = 'TYPE:type message:message'
output = [(
type: 'type'
text: 'message'
filePath: null
range: [[0, 0], [0, 0]]
)]
results = helpers.parse(input, regex, {flags: "gi"})
expect(results).toEqual(output)

describe '::find', ->
it 'cries when no argument is passed', ->
expect ->
Expand Down
4 changes: 3 additions & 1 deletion src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,9 @@ export function parse(data, regex, opts = {}) {
}

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

const messages = []
const compiledRegexp = NamedRegexp(regex, options.flags)
Expand Down

0 comments on commit d78b20c

Please sign in to comment.