fix: import-name options bugs and documentation#882
fix: import-name options bugs and documentation#882dosentmatter wants to merge 3 commits intomicrosoft:masterfrom
import-name options bugs and documentation#882Conversation
|
Wonder why Travis CI is failing lint for node 6. The previous build failed too. |
import-name options bugs and documentationimport-name options bugs and documentation
import-name options bugs and documentationimport-name options bugs and documentation
|
@dosentmatter thank you for the interest and PR. Will check it on weekend. As for Node 6 - it was shipped with npm v3 that doesn't support |
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`.
Add documentation and examples of all the `import-name` options.
|
Actually, I made a mistake. Currently, The current functionality is the following: import Foo from './foo';
import Foo from './Foo';
import foo from './foo';
import Foo from './foo';
import foo from './foo';
import Foo from './foo';
import foo from './Foo';
import Foo from './foo';What this means is that
|
`camelCase` currently allows the first letter to be uppercase by enforcing that it matches the casing of the file name first letter. Enforce the first letter to be lowercase.
IllusionMH
left a comment
There was a problem hiding this comment.
Overall changes to docs and code (except now redundant update to makeCamelCase) looks good, however this will be breaking change and might require better approach.
| <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>. |
There was a problem hiding this comment.
Is this change because of defaults?
| 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.
| To not ignore this rule for external modules, add this configuration: <code>'import-name': [true, null, null, { ignoreExternalModule: false }]</code>. | |
| To apply this rule for external modules, add this configuration: <code>'import-name': [true, null, null, { ignoreExternalModule: false }]</code>. |
|
|
||
| function makeCamelCase(input: string): string { | ||
| return input.replace( | ||
| let result = `${input.charAt(0)}${input.slice(1)}`; |
There was a problem hiding this comment.
Doesn't look like this changes anything (without .toLowerCase())
| "version": "2.1.1", | ||
| "bundled": true, | ||
| "dev": true, | ||
| "optional": true |
There was a problem hiding this comment.
Could you please rollback these changes to package-lock.json?
| 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.
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 6.0.0.
Looks like better solution is needed to avoid breaking change for those who added one more element to options array to match expected indices
|
I think that it might be possible to avoid breaking change with checks of structure check arguments length and then types arguments e.g. @dosentmatter @JoshuaKGoldberg what do you think on about this approach? Is it possible to do it in general case? Is it worth to implement or better to consider earlier |
|
Hey @IllusionMH, thanks for the review. I'll get to them when I have time. But I just want to respond to one of your comments first before I lose my train of thought.
I don't think it is possible to retain complete compatibility with the old code. The old code allowed element 0 to be any type, not just falsy values. It was completely ignored. So let's go over the case with a s length 1 options array: [{}]
[true]
[undefined]
[null]
[{ 'React': 'react' }]
[{ 'Foo': './foo' }]Although it is unlikely for someone to have an options array like this, all of these used to be ignored. If we now go and pass it to However, maybe we can assume that not many people knew how to skip the 0th element. The base tslint.json just used The only way you would know for sure to skip the 0th element is if you read the code, which is how I found it out. |
|
Closing this PR per #876. It's always sad to see good work being closed, but we don't have the staffing or relevancy to take on more features. Thanks everyone! |
PR checklist
Overview of change:
import-namerule has an off-by-one bug where it selects options starting from the wrong index. I updated the tests to match this.I also noticed that for
camelCase, it allowed the first letter to be upper-case.any-caseis eitherPascalCaseorcamelCase, but sincecamelCaseallowed the first letter to be upper case,any-caseandcamelCaseare currently the same. I enforced the first letter to be lowercase.I also updated the documentation. It's a bit lacking right now. It doesn't explain all of the allowed options.
Is there anything you'd like reviewers to focus on?
Not completely related but, I found this bug from #881. In #881, I had other problems.