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

#451 : Add logic to support more specifiers for import-name #522

Conversation

monicbhanushali
Copy link
Contributor

This PR fixes #451

  • Updated import-name validation logic to include more specifiers as replacement-keys
  • Added test case

@msftclas
Copy link

msftclas commented Oct 6, 2018

CLA assistant check
All CLA requirements met.

moduleName = this.makeCamelCase(moduleName);
if (this.isImportNameValid(importedName, moduleName) === false) {
const message: string = `Misnamed import. Import should be named '${moduleName}' but found '${importedName}'`;
let expectedImportedName = moduleName.replace(/.*\//, ''); // chop off the path
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the variable name moduleName to expectedModuleName as it was confusing.
Also the primary reason for new variable was to make sure that we aren't changing the input we get which the code was doing earlier.

return Utils.exists(Object.keys(this.replacements), (replacementKey: string): boolean => {
if (new RegExp(replacementKey).test(moduleName)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I replaced this Regex check with exact string match because in scenarios like below, the regex would match for both the import-names

import abc from 'fs/my-package'
import pqr from 'super/my-package'

Copy link

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code generally looks good! Could you please update the rule's documentation metadata to mention the new options?

Right, no new options - never mind! This looks great; thanks for the PR!

tslint-warnings.csv Show resolved Hide resolved
@JoshuaKGoldberg JoshuaKGoldberg merged commit 98b6ec2 into microsoft:master Oct 7, 2018
@JoshuaKGoldberg JoshuaKGoldberg added this to the 6.0.0-beta0 milestone Nov 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow more forms of specifiers in the config for import-name
3 participants