-
Notifications
You must be signed in to change notification settings - Fork 506
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
ktlint raise error when there is empty enum class #1711
Labels
Milestone
Comments
Tnx for reporting. It seems a rare edge case to me. I will skip it for the upcoming release (0.48) and fix it later. |
paul-dingemans
added
ktlint-official-codestyle
trailing-comma rule
and removed
ktlint-official-codestyle
labels
Nov 23, 2022
paul-dingemans
added a commit
that referenced
this issue
Feb 18, 2023
…ling-comma-on-declaration-site` Closes #1711
6 tasks
paul-dingemans
added a commit
that referenced
this issue
Mar 4, 2023
= Typealias EditorConfigProperties The typealias EditorConfigProperties was not used consistently in the KtLint code base. Some methods used the underlying data type Map<String, Property> instead. The EditorConfig enforces a consistent usage as it fully encapsulates the Map<String, Property> data type. Also, the EditorConfig has a secondary constructor with a vararg arguments which results in better readable code. The interface UsesEditorConfigProperties which optionally could be implemented on a Rule class is replaced with a property in the Rule class. If a rule wants to read a property from the EditorConfig, the property has to be registered in the field usesEditorConfigProperties of the Rule class. The RuleExecution context which provides the EditorConfig in the call to the beforeFirstNode function of the Rule instance only provides the properties that are registered in the field usesEditorConfigProperties. The "end_of_line" property has been transformed to an official EditorConfigProperty END_OF_LINE_PROPERTY and has been added to the default editor config properties. The value "native" has been dropped as this value is not recognized by the ec4j library nor IntelliJ IDEA. The EditorConfigGenerator has been simplified as the EditConfig can not contain multiple properties with the same name but having different Property definitions. Fixed a problem in FORCE_MULTILINE_WHEN_PARAMETER_COUNT_GREATER_OR_EQUAL_THAN_PROPERTY the old default value -1 is not accepted as it is not a positive integer. Fixed a problem in the EditorConfigLoader when ignoreEditorConfigOnFileSystem is enabled. The editorConfigDefaults will only be taken into account whenever the ec4j library is queried to retrieve the editor config for an extension at an existing path. This flag is supposed to be enabled while running unit tests which should not be affected by a '.editorconfig' file which exists on the filesystem where the tests are executed. For now, it is assumed that the file system does not contain such file in the root of the file system. Create extension function to transform an EditorConfigProperty to an ec4j Property with a value. Do not throw exception when enum class does not contain entries. Closes #1711 = Avoid class cast exceptions when retrieving a property without (ec4j) type Both the rules provided by Ktlint and custom rules can define properties with property types that are unknown to ec4j. If such custom property types are not provided to the ec4j library when reading the ".editorconfig" file this results in a property with a null type. Parsing a value of such a property always results in a value of type String which might not corresponding with the real type of the property. Another problem is that ec4j expects the name of a property to be identical to the name of the corresponding PropertyType. When no propertyType is found with a name identical to the name of the property, the type of the property becomes null. When building a property using the "Property.Builder" of ec4j, it is not possible to create a property having a null type. But when loading an ".editorconfig" file containing a custom property for which the propertyType was not registered in the EditorConfigLoader of ec4j does result in such a property. Closes #1806 Problems above are mitigated as follows: Wrap the ec4j EditorConfigLoader into EditorConfigLoaderEc4j and ensure that only the latter class is calling the ec4j EditorConfigLoader. Enforce that the EditorConfigDefaults can only be loaded when the propertyTypes have been given. When retrieving a value for an EditorConfigProperty from EditorConfig then always ignore the type of the ec4j property but use the type of the EditorConfigProperty itself. Add KtlintTestFileSystem as test utility whenever testing with ".editorconfig" files. Refactor all tests doing so. = Replace KtLintRuleEngine parameter "ignoreEditorConfigOnFileSystem" with "fileSystem" This property is primarily intended to be used in unit tests. By specifying an alternative FileSystem the unit test gains control on whether the EditorConfigLoader should or should not read specific ".editorconfig" files. For example, it is considered unwanted that a unit test is influenced by the ".editorconfig" file of the project in which the unit test is included. = Do not expose rule runners from RuleExecutionContext in case the rule is disabled. After loading the EditorConfig it can be determined which rules are enabled or disabled. The "EditorConfig.get(EditorConfigProperty)" function can not be used for this as this would require such properties to be created dynamically. As those properties are required only to decide which rules are executed, it does not make sense to store them in the EditorConfig that is used for propagation of properties to the rules. The logic which determine whether a rule is enabled or disabled is moved to RuleFilters. The RuleExecutionRuleFilter contains the logic extracted from the VisitorProvider. Likewise the RunAfterRuleFilter contains the logic which is extracted from the the RuleRunnerSorter. The RuleFilters are applied by the RuleExecutionContext before exposing them to the VisitorProvider. As of that the VisitorProvider now receives a set of RuleRunners that are enabled.
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
Expected Behavior
When kotlin project has empty enum class, ktlint raise error.
Observed Behavior
Steps to Reproduce
Your Environment
.editorconfig
settings : https://github.com/ganadist/VersionCodeDemo/blob/ktlint_0471_error/.editorconfigThe text was updated successfully, but these errors were encountered: