Skip to content
Permalink
Browse files

Update: Use characters instead of code units for `max-len` (#7299)

* Update: Use characters instead of code units for `max-len`

* Note the counting method in the docs

* Remove extra sentence about code units vs codepoints

* s/unicode/Unicode/
  • Loading branch information...
not-an-aardvark authored and nzakas committed Oct 7, 2016
1 parent c9a7ec5 commit 756bc5a62607fbbcdfcf403b2cb33009d5cb1569
Showing with 23 additions and 5 deletions.
  1. +1 −3 docs/rules/max-len.md
  2. +1 −1 lib/rules/max-len.js
  3. +21 −1 tests/lib/rules/max-len.js
@@ -8,9 +8,7 @@ var foo = { "bar": "This is a bar.", "baz": { "qux": "This is a qux" }, "difficu

## Rule Details

This rule enforces a maximum line length to increase code readability and maintainability.

**Note:** This rule calculates the length of a line via code units, not characters. That means if you use a double-byte character in your code, it will count as 2 code units instead of 1, and 2 will be used to calculate line length. This is a technical limitation of JavaScript that is made easier with ES2015, and we will look to update this when ES2015 is available in Node.js.
This rule enforces a maximum line length to increase code readability and maintainability. The length of a line is defined as the number of Unicode characters in the line.

## Options

@@ -107,7 +107,7 @@ module.exports = {

extraCharacterCount += spaceCount - 1; // -1 for the replaced tab
});
return line.length + extraCharacterCount;
return Array.from(line).length + extraCharacterCount;
}

// The options object must be the last option specified…
@@ -158,7 +158,13 @@ ruleTester.run("max-len", rule, {
},

// blank line
""
"",

// Multi-code-point unicode glyphs
{
code: "'🙂😀😆😎😊😜😉👍'",
options: [10]
}
],

invalid: [
@@ -502,6 +508,20 @@ ruleTester.run("max-len", rule, {
column: 1
}
]
},

// Multi-code-point unicode glyphs
{
code: "'🙁😁😟☹️😣😖😩😱👎'",
options: [10],
errors: [
{
message: "Line 1 exceeds the maximum line length of 10.",
type: "Program",
line: 1,
column: 1
}
]
}
]
});

0 comments on commit 756bc5a

Please sign in to comment.
You can’t perform that action at this time.