Skip to content

Commit

Permalink
Fix options can be undefined instead of having a default value (#10)
Browse files Browse the repository at this point in the history
When an import is something like the below,

import something from '../../some/folder';

Currently this plugin cannot fix that to be like,

import something from 'src/some/folder';

This because the `rootDir` variable in the `isParentFolder` function is
treated as `undefined` unless a user set that variable by its option.

So that this patch will fix this that `rootDir` not to be `undefined`,
rather it makes that an empty string by setting a default value.

In the case of `allowSameFolder`, `undefined` will be treated as `false`
so it has been doing as it should be.

It fixes #9.

Signed-off-by: Deokgyu Yang <secugyu@gmail.com>
  • Loading branch information
awesometic authored Jun 28, 2022
1 parent dd49a11 commit 1a20e7c
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ module.exports = {
fixable: "code",
},
create: function (context) {
const { allowSameFolder, rootDir } = context.options[0] || {};
const { allowSameFolder, rootDir } = {
allowSameFolder: context.options[0].allowSameFolder || false,
rootDir: context.options[0].rootDir || '',
};

return {
ImportDeclaration: function (node) {
Expand Down

0 comments on commit 1a20e7c

Please sign in to comment.