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

How to enable only the max_length of variable_name rule? #541

Closed
dacchan opened this issue Feb 16, 2016 · 10 comments
Closed

How to enable only the max_length of variable_name rule? #541

dacchan opened this issue Feb 16, 2016 · 10 comments

Comments

@dacchan
Copy link

dacchan commented Feb 16, 2016

Hello.

In SwiftLint at version v0.6.0 , I want only variable_name_max_length rule to be enabled.
However, I do not know the settings for latest version.

Is there any method to only the max_length of variable_name rule to be enabled?

.swiftlint.yml file.

# at v0.6.0
disabled_rules:
  - force_cast
  - force_try
  - function_body_length
  - line_length
  - nesting
  - todo
  - type_body_length
  - type_name
  - variable_name
  - variable_name_min_length
file_length:
  warning: 500
variable_name_max_length:
  warning: 45
  error: 60
@norio-nomura
Copy link
Collaborator

Could you please use lowest threshold?

variable_name:
  max_length:
    warning: 45
    error: 60
  min_length:
    warning: 1

You can confirm how configuration is interpreted by swiftlint

swiftlint rules --config ~/.swiftlint-test.yml
Loading configuration from '/Users/norio/.swiftlint-test.yml'
+-----------------------------+--------+-------------+------------------------+--------------------------------------------------+
| identifier                  | opt-in | correctable | enabled in your config | configuration                                    |
+-----------------------------+--------+-------------+------------------------+--------------------------------------------------+
| closing_brace               | no     | yes         | yes                    | warning                                          |
| colon                       | no     | yes         | yes                    | warning                                          |
| comma                       | no     | yes         | yes                    | warning                                          |
| conditional_binding_cascade | no     | no          | yes                    | warning                                          |
| control_statement           | no     | no          | yes                    | warning                                          |
| custom_rules                | no     | no          | yes                    | user-defined                                     |
| cyclomatic_complexity       | no     | no          | yes                    | warning: 10, error: 20                           |
| empty_count                 | yes    | no          | no                     | error                                            |
| file_length                 | no     | no          | yes                    | warning: 400, error: 1000                        |
| force_cast                  | no     | no          | yes                    | error                                            |
| force_try                   | no     | no          | yes                    | error                                            |
| force_unwrapping            | yes    | no          | no                     | warning                                          |
| function_body_length        | no     | no          | yes                    | warning: 40, error: 100                          |
| function_parameter_count    | no     | no          | yes                    | warning: 5, error: 8                             |
| leading_whitespace          | no     | no          | yes                    | warning                                          |
| legacy_constant             | no     | yes         | yes                    | warning                                          |
| legacy_constructor          | no     | yes         | yes                    | warning                                          |
| line_length                 | no     | no          | yes                    | warning: 100, error: 200                         |
| missing_docs                | yes    | no          | no                     | warning: public                                  |
| nesting                     | no     | no          | yes                    | warning                                          |
| opening_brace               | no     | yes         | yes                    | warning                                          |
| operator_whitespace         | no     | no          | yes                    | warning                                          |
| return_arrow_whitespace     | no     | no          | yes                    | warning                                          |
| statement_position          | no     | yes         | yes                    | warning                                          |
| todo                        | no     | no          | yes                    | warning                                          |
| trailing_newline            | no     | yes         | yes                    | warning                                          |
| trailing_semicolon          | no     | yes         | yes                    | warning                                          |
| trailing_whitespace         | no     | yes         | yes                    | warning                                          |
| type_body_length            | no     | no          | yes                    | warning: 200, error: 350                         |
| type_name                   | no     | no          | yes                    | (min_length) w/e: 3/0, (max_length) w/e: 40/1000 |
| valid_docs                  | no     | no          | yes                    | warning                                          |
| variable_name               | no     | no          | yes                    | (min_length) w: 1, (max_length) w/e: 45/60       |
+-----------------------------+--------+-------------+------------------------+--------------------------------------------------+

@jpsim jpsim added the question label Feb 16, 2016
@dacchan
Copy link
Author

dacchan commented Feb 18, 2016

I don't want to enable this rule.

Variable names should only contain alphanumeric characters and start with a lowercase character or should only contain capital letters.

@norio-nomura
Copy link
Collaborator

Oh, I understand. I thought only about length.
This is enhancement request to variable_name:

  • Enable/disable checking that is alphanumeric.
  • Enable/disable checking that start with a lower case character.

@dacchan
Copy link
Author

dacchan commented Feb 22, 2016

Thank you very much for your advice.

@scottrhoyt
Copy link
Contributor

This would have been possible before the merging of variable_name_min_length and variable_name_max_length with variable_name. At the time, the justification was that it would be most convenient for users to specify all their variable naming rules in one configuration and avoiding duplication of excluded. Forcing the use of alphanumeric lower case variables is also in line with most Swift style guides. However, if there is enough support for this type of use case, we could consider breaking the rules up again.

@gemmakbarlow
Copy link

@scottrhoyt I'd love to see the alphanumeric rule become optional; we're porting a codebase to use SwiftLint now, and the more granular the rules, the smaller the PRs to do so.

@Tableau-David-Potter
Copy link
Contributor

Tableau-David-Potter commented Oct 22, 2016

+1
We declare our private properties with an underscore prefix. The length and content rules should be controllable separately.

For some reason this part of the rule just started firing when I converted the code to Swift 3.

@freak4pc
Copy link
Contributor

freak4pc commented Apr 6, 2017

Was this eventually done? Another issue with this is some people define Rx Observable using a $ sign at the end. I would want to disable the alphanumeric validation or at least allow specific characters.

@jaherhi
Copy link
Contributor

jaherhi commented Apr 14, 2017

If nobody's working on this, I could try adding the configurations mentioned, and open a PR once they're ready 🙂

@marcelofabri
Copy link
Collaborator

Fixed in #1444

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants