Please Support swiftformat:(disable|enable):<scope> (all|<rule>…) comments, which would disable/enable rules from the appropriate scope.
This will avoid needing to disable then enable (or vice verse).
Potential scopes:
declaration
signature
parameters
parameter
statement
expression
statement
Taking statement as an example:
If the comment is within the middle of (not before or after) a current statement, then statement applies the given disable/enable to everything within the current statement from the comment's line to the end of the current statement.
If the comment is before or after (not within the middle of) a statement:
- if the comment is on the same line as the previous statement, then
statement applies the given disable/enable to everything within the previous statement on the comment's line.
- if the comment that the line is on does not contain any of the previous statement, then
statement applies the given disable/enable to everything within the next statement within the same block. If there is no next statement within the block, it applies to nothing, and should be flagged with a warning or error.
e.g. (note that the code listed as having rule disabled also include the appropriate whitespace):
// `rule` is disabled only for `let x = [`, `c(),` & `d(),` & the closing `]`
a(); b(); let x = [ // swiftformat:disable:statement rule
c(),
d(),
]; e()
// `rule` is disabled only for `c(),`, `d(),` & the closing `]`
a(); let x = [
b(),
c(), // swiftformat:disable:statement rule
d(),
]; e()
// `rule` is disabled only for the closing `]`
a(); let x = [
b(),
c(),
d(),
] // swiftformat:disable:statement rule
e()
// warning/error
{
a()
// swiftformat:disable:statement rule
}
// `rule` is disabled only for `b()`
{
a()
// swiftformat:disable:statement rule
b()
}
// `rule` is disabled only for `b()`
{
a()
b() // swiftformat:disable:statement rule
c()
}
// `rule` is disabled only for `b()`
{
a(); b() // swiftformat:disable:statement rule
c()
}
// `rule` is disabled only for `b()`
{
a() +
b() // swiftformat:disable:statement rule
c()
}
// `rule` is disabled only for `a() + b()`
{
a() + // swiftformat:disable:statement rule
b()
c()
}
// `rule` is disabled only for `a() + b()`
{
// swiftformat:disable:statement rule
a() +
b()
c()
}
other scopes
Either each scope could have its own keyword, or maybe scopes where context would provide disambiguation could share keywords (e.g., statement & expression can't be disambiguated by context, and parameters & parameter also can't be disambiguated by context).
We could refine behavior for each scope once we have an exhaustive list of supported scopes, keywords, etc.
Please Support
swiftformat:(disable|enable):<scope> (all|<rule>…)comments, which would disable/enable rules from the appropriate scope.This will avoid needing to
disablethenenable(or vice verse).Potential scopes:
declarationsignatureparametersparameterstatementexpressionstatement
Taking
statementas an example:If the comment is within the middle of (not before or after) a current statement, then
statementapplies the given disable/enable to everything within the current statement from the comment's line to the end of the current statement.If the comment is before or after (not within the middle of) a statement:
statementapplies the given disable/enable to everything within the previous statement on the comment's line.statementapplies the given disable/enable to everything within the next statement within the same block. If there is no next statement within the block, it applies to nothing, and should be flagged with a warning or error.e.g. (note that the code listed as having
ruledisabled also include the appropriate whitespace):other scopes
Either each scope could have its own keyword, or maybe scopes where context would provide disambiguation could share keywords (e.g., statement & expression can't be disambiguated by context, and parameters & parameter also can't be disambiguated by context).
We could refine behavior for each scope once we have an exhaustive list of supported scopes, keywords, etc.