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
'max-len' conflict with 'function-paren-newline' #9411
Comments
Thanks for the report. I'm not sure about the best solution for this. On the one hand, I'm not fully convinced that it needs to be fixed at all. With sufficiently long identifier names, In the past, we've generally avoided adding options related to the text length of a piece of code -- see #7526 for the reasoning. That said, I acknowledge there's a usability concern here -- I noticed a similar thing in #8102 when creating the |
Thanks for the thoughtful consideration.
Sure, but the case of ultra-long identifiers seems very rare. A simple chain of higher-order functions with descriptive names like what I posted is much more common. It's unacceptable to me that a modern formatter has no solution here. We have higher-order components like this all around the projects we work on at my job, and the identifiers aren't crazy-verbose. Checking the AST for a measure of complexity also kind of seems like a road to ruin, liable to produce allow some weird unexpected results when code is tersely written. I'd like to think there is a better way. I don't understand why rules in principle can't look at (certain) other rules. You say the reason is that "since it has to be possible to enable/disable rules independently". But this would be possible even with interdependent rules. If a user configured If you're worried about circular dependencies between formatting rules (a legitimate concern), one solution could be to elevate Here's the crux: I think it's fair to expect Line length is one of the most crucial code formatting criteria. It's more like a super-criterion. It's not just another rule. This is one of the things that Prettier got spectacularly right from the start. Prettier has subtly changed the way people think about line-length, correctly putting max line-length conceptually "at the top" of the formatting configuration. Everything has to be considered within the constraints of line-length. I would like to see ESLint assimilate this insight, in order to solve problems like this one. |
Thanks for continuing the discussion. I have a few thoughts on what you said:
Since ESLint was created, there has been a consistent design goal that rules should not be able to know about other rules. There are a few reasons for this:
There are a few more details I could go into on this point; to summarize, I think it's extremely unlikely that we will make a change that allows rules to see the configuration of other rules. If we're going to resolve the usability issue you've brought up with I should mention that we do have a
This isn't really true.
In general, I think it's definitely not safe to assume that a user has expressed a preferred line length in their config.
Keep in mind that ESLint is a linter, not a code formatter -- its main use case is pointing out potential problems in code, and allowing users to supplement it by adding their own rules. This means that ESLint rules have to make formatting decisions based on an unknown set of preferences that could be modified by the user at runtime. Prettier operates under a different set of design constraints, in that all possible options that could be provided by the user are known at development time. This means Prettier can use the preferred line length (along with some other preferences) to make very sophisticated formatting choices, but it also means that Prettier less configurable than ESLint in that it's not possible to create plugins that make arbitrary modifications to the formatting. I'm also not really convinced that there is anything special about the max line length preference as opposed to other stylistic preferences, e.g. the choice of whether to put spaces after commas. The latter would cause the length of a line to be modified, which could similarly change the desired formatting for any given maximum line length preference. |
I have this bit from a const isLocalhost = Boolean(
window.location.hostname === 'localhost' ||
// [::1] is the IPv6 localhost address.
window.location.hostname === '[::1]' ||
// 127.0.0.1/8 is considered localhost for IPv4.
window.location.hostname.match(
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/,
),
); |
Hi, I understand everyone's arguments in this issue, but I would love an addendum to the So, I guess I wish both rules met the same criteria for // array-element-newline: ['error', 'multiline']
const shortArray = [1, 2, 3];
const longArray = [
'someReallyLongString',
'letsImagineThatAllOnOneLineTheseWouldCrossOurMaxLenThreshold',
'puppies'
]; Does that seem reasonable? Thank you for your time. |
Thanks for your interest in improving ESLint. Unfortunately, it looks like this issue didn't get consensus from the team, so I'm closing it. We define consensus as having three 👍s from team members, as well as a team member willing to champion the proposal. This is a high bar by design -- we can't realistically accept and maintain every feature request in the long term, so we only accept feature requests which are useful enough that there is consensus among the team that they're worth adding. Since ESLint is pluggable and can load custom rules at runtime, the lack of consensus among the ESLint team doesn't need to be a blocker for you using this in your project, if you'd find it useful. It just means that you would need to implement the rule yourself, rather than using a bundled rule that is packaged with ESLint. |
thanks, @not-an-aardvark. for posterity, i did implement my versions of the rules i commented about ( |
There currently appears to be no way to use
function-paren-newline
in a way that takes account of maximum line length. With the defaultmultiline
option and a function with a single long parameter name, there is no way to format the code without violating eitherfunction-paren-newline
ormax-len
. Examples:triggers the error
Unexpected newline after "("
.triggers the error twice:
Triggers the
max-len
error. If there is an error-free formatting solution given the current defaults, please educate me!If this is a bug, one possibility could be to make the existing
multiline
option sensitive to max line length. Another could be to create a new option.ESLint Version: 4.8.0
Node Version: 6.11.1
npm Version: 5.2.0
eslintrc
{
This issue originally raised at airbnb/javascript#1584
The text was updated successfully, but these errors were encountered: