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

New Add vue/no-potential-property-typo rule #1072

Merged

Conversation

IWANABETHATGUY
Copy link
Contributor

@IWANABETHATGUY IWANABETHATGUY changed the title Feature/no potential property typo Feature/no potential property typo (WIP) Mar 9, 2020
@IWANABETHATGUY
Copy link
Contributor Author

i make a new rule , no-potential-typo rule to warn user a potential typo error, when user define a custom component option is similar to vue built-in option, here is an example;

export default {
  // ok 
  data() {

  },
  // ok , this maybe a custom property
  testtt: {},
  // bad, this is more likely to be  a typo
  method: {}
}

@ota-meshi
Copy link
Member

Hi @IWANABETHATGUY.
I think it is difficult to judge typos automatically.
I'm worried that this rule may require users to use more suppression comments.

I like a rule to have users set a whitelist and report non-whitelist properties. e.g. no-unknown-component-options rule.
Users can also add properties such as beforeRouteEnter.

https://router.vuejs.org/guide/advanced/navigation-guards.html#in-component-guards

I like to list similar names in the whitelist as a suggestion to fix the wrong property.

What do you think?

@IWANABETHATGUY
Copy link
Contributor Author

beforeRouterLeave is absolute alright for this rule, usually when two string editdistance is. greater than 0 and lessEqual than 1 we report that warning,
here is the built-in options lib/utils/vue-component-options.json, we could default this rule for warning not a error.
i don't think people will define a component option like this

export default {
  dat() {},
  method: {},
  comput: {},
  filter: {}
}

we default the threshold is 1, only the option in code is very similar but not a vue built-in option will report. we don't check the inner property, so i think this is safe for user;
what do you think?

@ota-meshi
Copy link
Member

ota-meshi commented Mar 10, 2020

I think people want to detect invalid properties. (The cause of the invalid property may be a typo.)
I think it makes sense to be able to check that properties other than those on the whitelist are not set as a result of the CI.
However, even if you can check that there are no typos (depends on edit distance) as a result of the CI, it doesn't make sense. Because the invalid property may remain.

I agree that define a component option whitelist is difficult.
We may wish to provide some whitelist presets.
e.g. Vue.js standard, router, nuxt and more.
Users can whitelist presets and custom property names.

(Sorry if you don't communicate well because I don't understand English well.)

@IWANABETHATGUY
Copy link
Contributor Author

bacuase the indent, the test case is pretty ugly, do you have some good idea for this? and do i need more test case for this rule?

@ota-meshi
Copy link
Member

Hi @IWANABETHATGUY!
I'm not sure if this rule is best, so I'd like to start with an issue #922.

@IWANABETHATGUY
Copy link
Contributor Author

@ota-meshi could you please help for review

@IWANABETHATGUY IWANABETHATGUY changed the title Feature/no potential property typo (WIP) Feature/no potential property typo Mar 18, 2020
@IWANABETHATGUY IWANABETHATGUY changed the title Feature/no potential property typo New Add vue/no-potential-property-typo rule Mar 18, 2020
Copy link
Member

@ota-meshi ota-meshi left a comment

Choose a reason for hiding this comment

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

Sorry for the late reply.
I have change requests.

lib/rules/no-potential-component-option-typo.js Outdated Show resolved Hide resolved
lib/rules/no-potential-component-option-typo.js Outdated Show resolved Hide resolved
tests/lib/rules/no-potential-component-option-typo.js Outdated Show resolved Hide resolved
lib/rules/no-potential-component-option-typo.js Outdated Show resolved Hide resolved
lib/rules/no-potential-component-option-typo.js Outdated Show resolved Hide resolved
@IWANABETHATGUY
Copy link
Contributor Author

i still have a change request, but i have some question, could please give me some tips?

@ota-meshi
Copy link
Member

I want you to add a test case that can verify that all of the names defined in vue-component-options.json are valid.

Copy link
Member

@ota-meshi ota-meshi left a comment

Choose a reason for hiding this comment

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

LGTM! thank you!

@ota-meshi ota-meshi merged commit d2c94a9 into vuejs:master May 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants