-
Notifications
You must be signed in to change notification settings - Fork 199
fix: import-name
options bugs and documentation
#882
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -184,11 +184,16 @@ We recommend you specify exact versions of lint libraries, including `tslint-mic | |||||
</td> | ||||||
<td> | ||||||
The name of the imported module must match the name of the thing being imported. For special characters (<code>-</code>, <code>.</code>, <code>_</code>) remove them and make the following character uppercase. | ||||||
For example, it is valid to name imported modules the same as the module name: <code>import Service = require('x/y/z/Service')</code> and <code>import Service from 'x/y/z/Service'</code>. | ||||||
For example, it is valid to name imported modules the same as the module name: <code>import Service = require('./x/y/z/Service')</code> and <code>import Service from './x/y/z/Service'</code>. | ||||||
But it is invalid to change the name being imported, such as: <code>import MyCoolService = require('x/y/z/Service')</code> and <code>import MyCoolService from 'x/y/z/Service'</code>. | ||||||
When containing special characters such as <code>import $$ from 'my-awesome_library';</code> the corresponding configuration would look like <code>'import-name': [true, { 'myAwesomeLibrary': '$$' }]</code>. | ||||||
Since version 2.0.9 it is possible to configure this rule with a list of exceptions. | ||||||
For example, to allow <code>underscore</code> to be imported as <code>_</code>, add this configuration: <code>'import-name': [ true, { 'underscore': '_' }]</code> | ||||||
The default is to ignore this rule for external modules <code>ignoreExternalModule: true</code> and to use camelCase <code>case: 'camelCase'</code>. | ||||||
To not ignore this rule for external modules, add this configuration: <code>'import-name': [true, null, null, { ignoreExternalModule: false }]</code>. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
To allow <code>underscore</code> to be imported as <code>_</code>, add this configuration: <code>'import-name': [true, { 'underscore': '_' }, null, { ignoreExternalModule: false }]</code>. | ||||||
To ignore this rule for <code>react</code> and <code>express</code>, add this configuration: <code>'import-name': [true, null, ['react', 'express'], { ignoreExternalModule: false }]</code>. | ||||||
To use PascalCase: <code>'import-name': [true, null, null, { case: 'PascalCase' }]</code>. | ||||||
To use camelCase or PascalCase: <code>'import-name': [true, null, null, { case: 'any-case' }]</code>. | ||||||
</td> | ||||||
<td>2.0.5</td> | ||||||
</tr> | ||||||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will be a breaking change. I thought that this might be side effect of migration to new rule format, however this behavior was in |
||
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); | ||
} | ||
}); | ||
|
@@ -233,12 +233,14 @@ function walk(ctx: Lint.WalkContext<Option>) { | |
} | ||
|
||
function makeCamelCase(input: string): string { | ||
return input.replace( | ||
let result = `${input.charAt(0)}${input.slice(1)}`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't look like this changes anything (without |
||
result = result.replace( | ||
/[-|\.|_](.)/g, // tslint:disable-next-line:variable-name | ||
(_match: string, group1: string): string => { | ||
return group1.toUpperCase(); | ||
} | ||
); | ||
return result; | ||
} | ||
|
||
function makePascalCase(input: string): string { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this change because of defaults?