Skip to content

Commit 2c347a4

Browse files
josephfrazierstefanbuck
authored andcommitted
helper-grammar-regex-collection: Ensure PYTHON_IMPORT doesn't match comments (#237)
This is done by using the [multiline flag] instead of matching a newline, then by moving the `^\s*` outside the non-capturing group. Test page: https://github.com/kewisch/pyamo/blob/38dc77a833492a22d8ff707001577489f49ba9d6/pyamo/utils.py#L81 [multiline flag]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/multiline
1 parent 8f34f3a commit 2c347a4

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

packages/helper-grammar-regex-collection/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const TYPESCRIPT_REFERENCE = /\/{3}\s?<reference path=['"]([^'"\s]+)['"]/g;
77
const DOCKER_FROM = /FROM\s([^\n]*)/g;
88
const VIM_PLUGIN = /(?:(?:(?:Neo)?Bundle(?:Lazy|Fetch)?)|Plug(?:in)?)\s['"]([^'"\s]+)['"]/g;
99
const RUST_CRATE = /(?:extern crate|use) ([^:; ]+)/g;
10-
const PYTHON_IMPORT = /(?:(?:\n|^)\s*import|from)\s([^\s]*)/g;
10+
const PYTHON_IMPORT = /^\s*(?:import|from)\s([^\s]*)/gm;
1111

1212
export {
1313
REQUIRE,

packages/helper-grammar-regex-collection/test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ const fixtures = {
174174
invalid: [
175175
'\simport foo',
176176
'\simport\nfoo',
177+
'# from the',
177178
],
178179
},
179180
};

0 commit comments

Comments
 (0)