|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 11 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
1.4 KB
|
| Line | |
|---|
| 1 | /**
|
|---|
| 2 | * @fileoverview Rule to flag octal escape sequences in string literals.
|
|---|
| 3 | * @author Ian Christian Myers
|
|---|
| 4 | */
|
|---|
| 5 |
|
|---|
| 6 | "use strict";
|
|---|
| 7 |
|
|---|
| 8 | //------------------------------------------------------------------------------
|
|---|
| 9 | // Rule Definition
|
|---|
| 10 | //------------------------------------------------------------------------------
|
|---|
| 11 |
|
|---|
| 12 | /** @type {import('../shared/types').Rule} */
|
|---|
| 13 | module.exports = {
|
|---|
| 14 | meta: {
|
|---|
| 15 | type: "suggestion",
|
|---|
| 16 |
|
|---|
| 17 | docs: {
|
|---|
| 18 | description: "Disallow octal escape sequences in string literals",
|
|---|
| 19 | recommended: false,
|
|---|
| 20 | url: "https://eslint.org/docs/latest/rules/no-octal-escape"
|
|---|
| 21 | },
|
|---|
| 22 |
|
|---|
| 23 | schema: [],
|
|---|
| 24 |
|
|---|
| 25 | messages: {
|
|---|
| 26 | octalEscapeSequence: "Don't use octal: '\\{{sequence}}'. Use '\\u....' instead."
|
|---|
| 27 | }
|
|---|
| 28 | },
|
|---|
| 29 |
|
|---|
| 30 | create(context) {
|
|---|
| 31 |
|
|---|
| 32 | return {
|
|---|
| 33 |
|
|---|
| 34 | Literal(node) {
|
|---|
| 35 | if (typeof node.value !== "string") {
|
|---|
| 36 | return;
|
|---|
| 37 | }
|
|---|
| 38 |
|
|---|
| 39 | // \0 represents a valid NULL character if it isn't followed by a digit.
|
|---|
| 40 | const match = node.raw.match(
|
|---|
| 41 | /^(?:[^\\]|\\.)*?\\([0-3][0-7]{1,2}|[4-7][0-7]|0(?=[89])|[1-7])/su
|
|---|
| 42 | );
|
|---|
| 43 |
|
|---|
| 44 | if (match) {
|
|---|
| 45 | context.report({
|
|---|
| 46 | node,
|
|---|
| 47 | messageId: "octalEscapeSequence",
|
|---|
| 48 | data: { sequence: match[1] }
|
|---|
| 49 | });
|
|---|
| 50 | }
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| 53 | };
|
|---|
| 54 |
|
|---|
| 55 | }
|
|---|
| 56 | };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.