Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Commit

Permalink
Fix import-name options indexing
Browse files Browse the repository at this point in the history
The options begin at index 0. The previous developer might have gotten
it mixed up with initial `true` in the config array which controls
`ruleSeverity`, not `ruleArguments`.
  • Loading branch information
dosentmatter authored and kevin-lau-kr committed Jul 19, 2019
1 parent 34f3347 commit b3b53d2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 43 deletions.
41 changes: 11 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/importNameRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ export class Rule extends Lint.Rules.AbstractRule {

if (options.ruleArguments instanceof Array) {
options.ruleArguments.forEach((opt: unknown, index: number) => {
if (index === 1 && isObject(opt)) {
if (index === 0 && isObject(opt)) {
result.replacements = this.extractReplacements(opt);
}

if (index === 2 && Array.isArray(opt)) {
if (index === 1 && Array.isArray(opt)) {
result.ignoredList = this.extractIgnoredList(opt);
}

if (index === 3 && isObject(opt)) {
if (index === 2 && isObject(opt)) {
result.config = this.extractConfig(opt);
}
});
Expand Down
12 changes: 2 additions & 10 deletions src/tests/ImportNameRuleTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ describe('importNameRule', (): void => {
`;

const options = [
true,
{
backbone: 'Backbone',
react: 'React',
Expand All @@ -132,7 +131,6 @@ describe('importNameRule', (): void => {
import pqr from 'my-module'
`;
const options = [
true,
{
'fs/package-name': 'pkg',
'abc-tag': 'abc',
Expand All @@ -151,7 +149,6 @@ describe('importNameRule', (): void => {
import Up from 'up-module'
`;
const options = [
true,
{
'fs/package-name': 'pkg',
'abc-tag': 'abc',
Expand All @@ -171,7 +168,6 @@ describe('importNameRule', (): void => {
import Up from 'up-module'
`;
const options = [
true,
{
'fs/package-name': 'pkg',
'abc-tag': 'abc',
Expand Down Expand Up @@ -251,7 +247,6 @@ describe('importNameRule', (): void => {
`;

const options = [
true,
{},
{},
{
Expand All @@ -268,7 +263,6 @@ describe('importNameRule', (): void => {
`;

const options = [
true,
{},
{},
{
Expand Down Expand Up @@ -301,7 +295,6 @@ describe('importNameRule', (): void => {
`;

const options = [
true,
{},
{},
{
Expand All @@ -318,7 +311,6 @@ describe('importNameRule', (): void => {
`;

const options = [
true,
{},
{},
{
Expand Down Expand Up @@ -351,15 +343,15 @@ describe('importNameRule', (): void => {
import GraphqlTag from 'x/y/z/graphql-tag';
import graphqlTag from 'x/y/z/graphql-tag';
`;
const options = [true, {}, {}, { case: 'any-case' }];
const options = [{}, {}, { case: 'any-case' }];
TestHelper.assertViolationsWithOptions(ruleName, options, script, []);
});

it('should fail', () => {
const script: string = `
import gTag from 'x/y/z/graphql-tag';
`;
const options = [true, {}, {}, { case: 'any-case' }];
const options = [{}, {}, { case: 'any-case' }];
TestHelper.assertViolationsWithOptions(ruleName, options, script, [
{
failure: "Misnamed import. Import should be named 'graphqlTag' or 'GraphqlTag' but found 'gTag'",
Expand Down

0 comments on commit b3b53d2

Please sign in to comment.