Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add fixer for no-internal-import and fix fixer for no-relative import #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/rules/no-internal-import.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import moduleVisitor, {
makeOptionsSchema,
} from 'eslint-module-utils/moduleVisitor';
import parse from 'parse-package-name';

import fs from 'fs';
import getPackages from 'get-monorepo-packages';
import path from 'path';
import minimatch from 'minimatch';
import fs from 'fs';
import parse from 'parse-package-name';
import path from 'path';

export const meta = {
schema: [makeOptionsSchema({})],
fixable: 'code'
};

const withoutExtension = (importFile, fileEntry) => {
Expand Down Expand Up @@ -76,6 +78,10 @@ export const create = context => {
context.report({
node,
message: `Import for monorepo package '${name}' is internal.`,
fix: function fix(fixer) {
const path = _path.parse(node.value).dir
return fixer.replaceText(node, '\'' + path + '\'');
}
});
}, moduleUtilOptions);
};
Expand Down
15 changes: 7 additions & 8 deletions src/rules/no-relative-import.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import resolve from 'eslint-module-utils/resolve';
import moduleVisitor, {
makeOptionsSchema,
} from 'eslint-module-utils/moduleVisitor';

import getPackages from 'get-monorepo-packages';
import isInside from 'path-is-inside';
import minimatch from 'minimatch';
import path from 'path';
import getPackages from 'get-monorepo-packages';
import resolve from 'eslint-module-utils/resolve';

export const meta = {
schema: [makeOptionsSchema({})],
Expand Down Expand Up @@ -37,12 +38,10 @@ export const create = context => {
node,
message: `Import for monorepo package '${pkg.package.name}' should be absolute.`,
fix: fixer => {
fixer.replaceText(
node,
`${pkg.package.name}${
subPackagePath !== '.' ? '/' + subPackagePath : ''
}`
);
const basePath = '' + pkg.package.name + (subPackagePath !== '.' ? '/' + subPackagePath : '')
const path = _path.parse(basePath).dir
const name = _path.parse(basePath).name
return fixer.replaceText(node, '\'' + (name !== '.' && name !== 'index' ? path + '/' + name : path) + '\'');
},
});
}, moduleUtilOptions);
Expand Down