GeezerVison is showing github.com — tools: non-Ascii linter for /lib only · nodejs/node@016a28a
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/.eslintrc.yaml +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 6 | 6 | buffer-constructor: error | 7 | 7 | no-let-in-for-declaration: error | 8 | 8 | lowercase-name-for-primitive: error | | 9 | + non-ascii-character: error |
Collapse file Copy file name to clipboardExpand all lines: lib/console.js +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -81,7 +81,7 @@ function createWriteErrorHandler(stream) { | 81 | 81 | // If there was an error, it will be emitted on `stream` as | 82 | 82 | // an `error` event. Adding a `once` listener will keep that error | 83 | 83 | // from becoming an uncaught exception, but since the handler is | 84 | | - // removed after the event, non-console.* writes won’t be affected. | | 84 | + // removed after the event, non-console.* writes won't be affected. | 85 | 85 | // we are only adding noop if there is no one else listening for 'error' | 86 | 86 | if (stream.listenerCount('error') === 0) { | 87 | 87 | stream.on('error', noop); | @@ -114,7 +114,7 @@ function write(ignoreErrors, stream, string, errorhandler, groupIndent) { | 114 | 114 | // even in edge cases such as low stack space. | 115 | 115 | if (e.message === 'Maximum call stack size exceeded') | 116 | 116 | throw e; | 117 | | - // Sorry, there’s no proper way to pass along the error here. | | 117 | + // Sorry, there's no proper way to pass along the error here. | 118 | 118 | } finally { | 119 | 119 | stream.removeListener('error', noop); | 120 | 120 | } | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/http2/core.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -1537,7 +1537,7 @@ function processRespondWithFD(fd, headers, offset = 0, length = -1, | 1537 | 1537 | return; | 1538 | 1538 | } | 1539 | 1539 | // exact length of the file doesn't matter here, since the | 1540 | | - // stream is closing anyway — just use 1 to signify that | | 1540 | + // stream is closing anyway - just use 1 to signify that | 1541 | 1541 | // a write does exist | 1542 | 1542 | trackWriteState(this, 1); | 1543 | 1543 | } | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/test/unicode.js +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 3 | 3 | // This module exists entirely for regression testing purposes. | 4 | 4 | // See `test/parallel/test-internal-unicode.js`. | 5 | 5 |
| | 6 | +/* eslint-disable non-ascii-character */ | 6 | 7 | module.exports = '✓'; | | 8 | +/* eslint-enable non-ascii-character */ |
Collapse file Copy file name to clipboardExpand all lines: lib/stream.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 45 | 45 | try { | 46 | 46 | Stream._isUint8Array = process.binding('util').isUint8Array; | 47 | 47 | } catch (e) { | 48 | | - // This throws for Node < 4.2.0 because there’s no util binding and | | 48 | + // This throws for Node < 4.2.0 because there's no util binding and | 49 | 49 | // returns undefined for Node < 7.4.0. | 50 | 50 | } | 51 | 51 | } | |
Collapse file Copy file name to clipboardExpand all lines: lib/timers.js +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -89,6 +89,7 @@ const TIMEOUT_MAX = 2147483647; // 2^31-1 | 89 | 89 | // TimerWrap C++ handle, which makes the call after the duration to process the | 90 | 90 | // list it is attached to. | 91 | 91 | // | | 92 | +/* eslint-disable non-ascii-character */ | 92 | 93 | // | 93 | 94 | // ╔════ > Object Map | 94 | 95 | // ║ | @@ -110,6 +111,7 @@ const TIMEOUT_MAX = 2147483647; // 2^31-1 | 110 | 111 | // ║ | 111 | 112 | // ╚════ > Linked List | 112 | 113 | // | | 114 | +/* eslint-enable non-ascii-character */ | 113 | 115 | // | 114 | 116 | // With this, virtually constant-time insertion (append), removal, and timeout | 115 | 117 | // is possible in the JavaScript layer. Any one list of timers is able to be | |
Collapse file Copy file name to clipboardExpand all lines: lib/zlib.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -339,7 +339,7 @@ Zlib.prototype.flush = function flush(kind, callback) { | 339 | 339 | this._scheduledFlushFlag = maxFlush(kind, this._scheduledFlushFlag); | 340 | 340 |
| 341 | 341 | // If a callback was passed, always register a new `drain` + flush handler, | 342 | | - // mostly because that’s simpler and flush callbacks piling up is a rare | | 342 | + // mostly because that's simpler and flush callbacks piling up is a rare | 343 | 343 | // thing anyway. | 344 | 344 | if (!alreadyHadFlushScheduled || callback) { | 345 | 345 | const drainHandler = () => this.flush(this._scheduledFlushFlag, callback); | |
Collapse file Copy file name to clipboard +61Lines changed: 61 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +/** | | 2 | + * @fileOverview Any non-ASCII characters in lib/ will increase the size | | 3 | + * of the compiled node binary. This linter rule ensures that | | 4 | + * any such character is reported. | | 5 | + | | 6 | + */ | | 7 | + | | 8 | +'use strict'; | | 9 | + | | 10 | +//------------------------------------------------------------------------------ | | 11 | +// Rule Definition | | 12 | +//------------------------------------------------------------------------------ | | 13 | + | | 14 | +const nonAsciiRegexPattern = /[^\r\n\x20-\x7e]/; | | 15 | +const suggestions = { | | 16 | + '’': '\'', | | 17 | + '‛': '\'', | | 18 | + '‘': '\'', | | 19 | + '“': '"', | | 20 | + '‟': '"', | | 21 | + '”': '"', | | 22 | + '«': '"', | | 23 | + '»': '"', | | 24 | + '—': '-' | | 25 | +}; | | 26 | + | | 27 | +module.exports = (context) => { | | 28 | + | | 29 | + const reportIfError = (node, sourceCode) => { | | 30 | + | | 31 | + const matches = sourceCode.text.match(nonAsciiRegexPattern); | | 32 | + | | 33 | + if (!matches) return; | | 34 | + | | 35 | + const offendingCharacter = matches[0]; | | 36 | + const offendingCharacterPosition = matches.index; | | 37 | + const suggestion = suggestions[offendingCharacter]; | | 38 | + | | 39 | + let message = `Non-ASCII character '${offendingCharacter}' detected.`; | | 40 | + | | 41 | + message = suggestion ? | | 42 | + `${message} Consider replacing with: ${suggestion}` : | | 43 | + message; | | 44 | + | | 45 | + context.report({ | | 46 | + node, | | 47 | + message, | | 48 | + loc: sourceCode.getLocFromIndex(offendingCharacterPosition), | | 49 | + fix: (fixer) => { | | 50 | + return fixer.replaceText( | | 51 | + node, | | 52 | + suggestion ? `${suggestion}` : '' | | 53 | + ); | | 54 | + } | | 55 | + }); | | 56 | + }; | | 57 | + | | 58 | + return { | | 59 | + Program: (node) => reportIfError(node, context.getSourceCode()) | | 60 | + }; | | 61 | +}; |
|