Regression - crash on import in TS module declaration
Closed this issue · 1 comments
I have another bug report, it's a regression related to #13. Fortunately, the fix seems to be trivial.
The plugin crashes on a file like this:
filetypes.d.ts
declare module '*.svg' {
import * as React from 'react'
const content: React.FunctionComponent<React.SVGAttributes<SVGElement>>
export default content
}
You'd want a declaration like this, when using SVGR in React. The error is:
TypeError: Cannot read properties of undefined (reading 'some')
Occurred while linting TEST\src\filetypes.d.ts:2
Rule: "import-newlines/enforce"
at getCommentsInsideImport (TEST\node_modules\eslint-plugin-import-newlines\lib\enforce.js:46:24)
...
My quick fix was to change node.parent.comments.some((comment) => {
to node.parent.comments && node.parent.comments.some((comment) => {
and the issue went away.
Good catch, this most likely affects any file without comments due to the nature of the issue. I released 1.3.4 with a fix and covered this with a test case to make sure it does not break in the future.