WIP: bootstrap and partial real Solana watcher implementation
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (C) 2012-2022 by various contributors (see AUTHORS)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
@@ -0,0 +1,73 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const scope_manager_1 = require("@typescript-eslint/scope-manager");
|
||||
const utils_1 = require("@typescript-eslint/utils");
|
||||
const util_1 = require("../util");
|
||||
function hasAssignmentBeforeNode(variable, node) {
|
||||
return (variable.references.some(ref => ref.isWrite() && ref.identifier.range[1] < node.range[1]) ||
|
||||
variable.defs.some(def => isDefinitionWithAssignment(def) && def.node.range[1] < node.range[1]));
|
||||
}
|
||||
function isDefinitionWithAssignment(definition) {
|
||||
if (definition.type !== scope_manager_1.DefinitionType.Variable) {
|
||||
return false;
|
||||
}
|
||||
const variableDeclarator = definition.node;
|
||||
return variableDeclarator.definite || variableDeclarator.init != null;
|
||||
}
|
||||
exports.default = (0, util_1.createRule)({
|
||||
name: 'no-non-null-asserted-nullish-coalescing',
|
||||
meta: {
|
||||
type: 'problem',
|
||||
docs: {
|
||||
description: 'Disallow non-null assertions in the left operand of a nullish coalescing operator',
|
||||
recommended: 'strict',
|
||||
},
|
||||
hasSuggestions: true,
|
||||
messages: {
|
||||
noNonNullAssertedNullishCoalescing: 'The nullish coalescing operator is designed to handle undefined and null - using a non-null assertion is not needed.',
|
||||
suggestRemovingNonNull: 'Remove the non-null assertion.',
|
||||
},
|
||||
schema: [],
|
||||
},
|
||||
defaultOptions: [],
|
||||
create(context) {
|
||||
return {
|
||||
'LogicalExpression[operator = "??"] > TSNonNullExpression.left'(node) {
|
||||
if (node.expression.type === utils_1.TSESTree.AST_NODE_TYPES.Identifier) {
|
||||
const scope = context.sourceCode.getScope(node);
|
||||
const identifier = node.expression;
|
||||
const variable = utils_1.ASTUtils.findVariable(scope, identifier.name);
|
||||
if (variable && !hasAssignmentBeforeNode(variable, node)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'noNonNullAssertedNullishCoalescing',
|
||||
/*
|
||||
Use a suggestion instead of a fixer, because this can break type checks.
|
||||
The resulting type of the nullish coalesce is only influenced by the right operand if the left operand can be `null` or `undefined`.
|
||||
After removing the non-null assertion the type of the left operand might contain `null` or `undefined` and then the type of the right operand
|
||||
might change the resulting type of the nullish coalesce.
|
||||
See the following example:
|
||||
|
||||
function test(x?: string): string {
|
||||
const bar = x! ?? false; // type analysis reports `bar` has type `string`
|
||||
// x ?? false; // type analysis reports `bar` has type `string | false`
|
||||
return bar;
|
||||
}
|
||||
*/
|
||||
suggest: [
|
||||
{
|
||||
messageId: 'suggestRemovingNonNull',
|
||||
fix(fixer) {
|
||||
const exclamationMark = (0, util_1.nullThrows)(context.sourceCode.getLastToken(node, utils_1.ASTUtils.isNonNullAssertionPunctuator), util_1.NullThrowsReasons.MissingToken('!', 'Non-null Assertion'));
|
||||
return fixer.remove(exclamationMark);
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,8 @@
|
||||
import type { TSESTree } from '@typescript-eslint/types';
|
||||
import { DefinitionBase } from './DefinitionBase';
|
||||
import { DefinitionType } from './DefinitionType';
|
||||
export declare class TSEnumMemberDefinition extends DefinitionBase<DefinitionType.TSEnumMember, TSESTree.TSEnumMember, null, TSESTree.Identifier | TSESTree.StringLiteral> {
|
||||
readonly isTypeDefinition = true;
|
||||
readonly isVariableDefinition = true;
|
||||
constructor(name: TSESTree.Identifier | TSESTree.StringLiteral, node: TSEnumMemberDefinition['node']);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
var array = require('postgres-array');
|
||||
|
||||
module.exports = {
|
||||
create: function (source, transform) {
|
||||
return {
|
||||
parse: function() {
|
||||
return array.parse(source, transform);
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,10 @@
|
||||
import parse from './parse.js';
|
||||
import { unsafeStringify } from './stringify.js';
|
||||
export default function v1ToV6(uuid) {
|
||||
const v1Bytes = typeof uuid === 'string' ? parse(uuid) : uuid;
|
||||
const v6Bytes = _v1ToV6(v1Bytes);
|
||||
return typeof uuid === 'string' ? unsafeStringify(v6Bytes) : v6Bytes;
|
||||
}
|
||||
function _v1ToV6(v1Bytes) {
|
||||
return Uint8Array.of(((v1Bytes[6] & 0x0f) << 4) | ((v1Bytes[7] >> 4) & 0x0f), ((v1Bytes[7] & 0x0f) << 4) | ((v1Bytes[4] & 0xf0) >> 4), ((v1Bytes[4] & 0x0f) << 4) | ((v1Bytes[5] & 0xf0) >> 4), ((v1Bytes[5] & 0x0f) << 4) | ((v1Bytes[0] & 0xf0) >> 4), ((v1Bytes[0] & 0x0f) << 4) | ((v1Bytes[1] & 0xf0) >> 4), ((v1Bytes[1] & 0x0f) << 4) | ((v1Bytes[2] & 0xf0) >> 4), 0x60 | (v1Bytes[2] & 0x0f), v1Bytes[3], v1Bytes[8], v1Bytes[9], v1Bytes[10], v1Bytes[11], v1Bytes[12], v1Bytes[13], v1Bytes[14], v1Bytes[15]);
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"misc.d.ts","sourceRoot":"","sources":["../src/misc.ts"],"names":[],"mappings":"AAUA,OAAO,EAEL,KAAK,OAAO,EAEZ,KAAK,YAAY,EAClB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAe,KAAK,OAAO,IAAI,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAgBlF,8DAA8D;AAC9D,eAAO,MAAM,MAAM,EAAE,OAInB,CAAC;AAWH,gEAAgE;AAChE,eAAO,MAAM,UAAU,EAAE,OAIvB,CAAC;AAOH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,UAAU,EAAE,eAAe,EAAE,UAAU,GAAG,YAAY,CAU3F;AAKD,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,UAAU,EAAE,eAAe,EAAE,UAAU,GAAG,YAAY,CAW7F;AAID,eAAO,MAAM,OAAO,EAAE,MAErB,CAAC;AACF,eAAO,MAAM,OAAO,EAAE,MAErB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,MAAM,EAAE,QASnB,CAAC;AACH;;GAEG;AACH,eAAO,MAAM,KAAK,EAAE,QASlB,CAAC"}
|
||||
@@ -0,0 +1 @@
|
||||
export { _ as default } from "../esm/_object_without_properties.js";
|
||||
@@ -0,0 +1,34 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.toUpperCase = exports.toLowerCase = exports.trim = exports.normalize = exports.overwrite = exports.mime = exports.property = exports.endsWith = exports.startsWith = exports.includes = exports.uppercase = exports.lowercase = exports.regex = exports.length = exports.minLength = exports.maxLength = exports.size = exports.minSize = exports.maxSize = exports.multipleOf = exports.nonnegative = exports.nonpositive = exports.negative = exports.positive = exports.minimum = exports.gte = exports.gt = exports.maximum = exports.lte = exports.lt = void 0;
|
||||
var index_js_1 = require("../core/index.cjs");
|
||||
Object.defineProperty(exports, "lt", { enumerable: true, get: function () { return index_js_1._lt; } });
|
||||
Object.defineProperty(exports, "lte", { enumerable: true, get: function () { return index_js_1._lte; } });
|
||||
Object.defineProperty(exports, "maximum", { enumerable: true, get: function () { return index_js_1._lte; } });
|
||||
Object.defineProperty(exports, "gt", { enumerable: true, get: function () { return index_js_1._gt; } });
|
||||
Object.defineProperty(exports, "gte", { enumerable: true, get: function () { return index_js_1._gte; } });
|
||||
Object.defineProperty(exports, "minimum", { enumerable: true, get: function () { return index_js_1._gte; } });
|
||||
Object.defineProperty(exports, "positive", { enumerable: true, get: function () { return index_js_1._positive; } });
|
||||
Object.defineProperty(exports, "negative", { enumerable: true, get: function () { return index_js_1._negative; } });
|
||||
Object.defineProperty(exports, "nonpositive", { enumerable: true, get: function () { return index_js_1._nonpositive; } });
|
||||
Object.defineProperty(exports, "nonnegative", { enumerable: true, get: function () { return index_js_1._nonnegative; } });
|
||||
Object.defineProperty(exports, "multipleOf", { enumerable: true, get: function () { return index_js_1._multipleOf; } });
|
||||
Object.defineProperty(exports, "maxSize", { enumerable: true, get: function () { return index_js_1._maxSize; } });
|
||||
Object.defineProperty(exports, "minSize", { enumerable: true, get: function () { return index_js_1._minSize; } });
|
||||
Object.defineProperty(exports, "size", { enumerable: true, get: function () { return index_js_1._size; } });
|
||||
Object.defineProperty(exports, "maxLength", { enumerable: true, get: function () { return index_js_1._maxLength; } });
|
||||
Object.defineProperty(exports, "minLength", { enumerable: true, get: function () { return index_js_1._minLength; } });
|
||||
Object.defineProperty(exports, "length", { enumerable: true, get: function () { return index_js_1._length; } });
|
||||
Object.defineProperty(exports, "regex", { enumerable: true, get: function () { return index_js_1._regex; } });
|
||||
Object.defineProperty(exports, "lowercase", { enumerable: true, get: function () { return index_js_1._lowercase; } });
|
||||
Object.defineProperty(exports, "uppercase", { enumerable: true, get: function () { return index_js_1._uppercase; } });
|
||||
Object.defineProperty(exports, "includes", { enumerable: true, get: function () { return index_js_1._includes; } });
|
||||
Object.defineProperty(exports, "startsWith", { enumerable: true, get: function () { return index_js_1._startsWith; } });
|
||||
Object.defineProperty(exports, "endsWith", { enumerable: true, get: function () { return index_js_1._endsWith; } });
|
||||
Object.defineProperty(exports, "property", { enumerable: true, get: function () { return index_js_1._property; } });
|
||||
Object.defineProperty(exports, "mime", { enumerable: true, get: function () { return index_js_1._mime; } });
|
||||
Object.defineProperty(exports, "overwrite", { enumerable: true, get: function () { return index_js_1._overwrite; } });
|
||||
Object.defineProperty(exports, "normalize", { enumerable: true, get: function () { return index_js_1._normalize; } });
|
||||
Object.defineProperty(exports, "trim", { enumerable: true, get: function () { return index_js_1._trim; } });
|
||||
Object.defineProperty(exports, "toLowerCase", { enumerable: true, get: function () { return index_js_1._toLowerCase; } });
|
||||
Object.defineProperty(exports, "toUpperCase", { enumerable: true, get: function () { return index_js_1._toUpperCase; } });
|
||||
@@ -0,0 +1,19 @@
|
||||
Copyright 2024 Justin Ridgewell <justin@ridgewell.name>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -0,0 +1,129 @@
|
||||
export declare enum CharacterCodes {
|
||||
EOF = -1,
|
||||
nullCharacter = 0,
|
||||
maxAsciiCharacter = 127,
|
||||
lineFeed = 10,// \n
|
||||
carriageReturn = 13,// \r
|
||||
lineSeparator = 8232,
|
||||
paragraphSeparator = 8233,
|
||||
nextLine = 133,
|
||||
space = 32,// " "
|
||||
nonBreakingSpace = 160,//
|
||||
enQuad = 8192,
|
||||
emQuad = 8193,
|
||||
enSpace = 8194,
|
||||
emSpace = 8195,
|
||||
threePerEmSpace = 8196,
|
||||
fourPerEmSpace = 8197,
|
||||
sixPerEmSpace = 8198,
|
||||
figureSpace = 8199,
|
||||
punctuationSpace = 8200,
|
||||
thinSpace = 8201,
|
||||
hairSpace = 8202,
|
||||
zeroWidthSpace = 8203,
|
||||
narrowNoBreakSpace = 8239,
|
||||
ideographicSpace = 12288,
|
||||
mathematicalSpace = 8287,
|
||||
ogham = 5760,
|
||||
replacementCharacter = 65533,
|
||||
_ = 95,
|
||||
$ = 36,
|
||||
_0 = 48,
|
||||
_1 = 49,
|
||||
_2 = 50,
|
||||
_3 = 51,
|
||||
_4 = 52,
|
||||
_5 = 53,
|
||||
_6 = 54,
|
||||
_7 = 55,
|
||||
_8 = 56,
|
||||
_9 = 57,
|
||||
a = 97,
|
||||
b = 98,
|
||||
c = 99,
|
||||
d = 100,
|
||||
e = 101,
|
||||
f = 102,
|
||||
g = 103,
|
||||
h = 104,
|
||||
i = 105,
|
||||
j = 106,
|
||||
k = 107,
|
||||
l = 108,
|
||||
m = 109,
|
||||
n = 110,
|
||||
o = 111,
|
||||
p = 112,
|
||||
q = 113,
|
||||
r = 114,
|
||||
s = 115,
|
||||
t = 116,
|
||||
u = 117,
|
||||
v = 118,
|
||||
w = 119,
|
||||
x = 120,
|
||||
y = 121,
|
||||
z = 122,
|
||||
A = 65,
|
||||
B = 66,
|
||||
C = 67,
|
||||
D = 68,
|
||||
E = 69,
|
||||
F = 70,
|
||||
G = 71,
|
||||
H = 72,
|
||||
I = 73,
|
||||
J = 74,
|
||||
K = 75,
|
||||
L = 76,
|
||||
M = 77,
|
||||
N = 78,
|
||||
O = 79,
|
||||
P = 80,
|
||||
Q = 81,
|
||||
R = 82,
|
||||
S = 83,
|
||||
T = 84,
|
||||
U = 85,
|
||||
V = 86,
|
||||
W = 87,
|
||||
X = 88,
|
||||
Y = 89,
|
||||
Z = 90,
|
||||
ampersand = 38,// &
|
||||
asterisk = 42,// *
|
||||
at = 64,// @
|
||||
backslash = 92,// \
|
||||
backtick = 96,// `
|
||||
bar = 124,// |
|
||||
caret = 94,// ^
|
||||
closeBrace = 125,// }
|
||||
closeBracket = 93,// ]
|
||||
closeParen = 41,// )
|
||||
colon = 58,// :
|
||||
comma = 44,// ,
|
||||
dot = 46,// .
|
||||
doubleQuote = 34,// "
|
||||
equals = 61,// =
|
||||
exclamation = 33,// !
|
||||
greaterThan = 62,// >
|
||||
hash = 35,// #
|
||||
lessThan = 60,// <
|
||||
minus = 45,// -
|
||||
openBrace = 123,// {
|
||||
openBracket = 91,// [
|
||||
openParen = 40,// (
|
||||
percent = 37,// %
|
||||
plus = 43,// +
|
||||
question = 63,// ?
|
||||
semicolon = 59,// ;
|
||||
singleQuote = 39,// '
|
||||
slash = 47,// /
|
||||
tilde = 126,// ~
|
||||
backspace = 8,// \b
|
||||
formFeed = 12,// \f
|
||||
byteOrderMark = 65279,
|
||||
tab = 9,// \t
|
||||
verticalTab = 11
|
||||
}
|
||||
//# sourceMappingURL=characterCodes.enum.d.ts.map
|
||||
@@ -0,0 +1,75 @@
|
||||
/**
|
||||
* @deprecated since v7.0.0
|
||||
* The version of the punycode module bundled in Node.js is being deprecated.
|
||||
* In a future major version of Node.js this module will be removed.
|
||||
* Users currently depending on the punycode module should switch to using
|
||||
* the userland-provided Punycode.js module instead.
|
||||
*/
|
||||
declare module 'punycode' {
|
||||
/**
|
||||
* @deprecated since v7.0.0
|
||||
* The version of the punycode module bundled in Node.js is being deprecated.
|
||||
* In a future major version of Node.js this module will be removed.
|
||||
* Users currently depending on the punycode module should switch to using
|
||||
* the userland-provided Punycode.js module instead.
|
||||
*/
|
||||
function decode(string: string): string;
|
||||
/**
|
||||
* @deprecated since v7.0.0
|
||||
* The version of the punycode module bundled in Node.js is being deprecated.
|
||||
* In a future major version of Node.js this module will be removed.
|
||||
* Users currently depending on the punycode module should switch to using
|
||||
* the userland-provided Punycode.js module instead.
|
||||
*/
|
||||
function encode(string: string): string;
|
||||
/**
|
||||
* @deprecated since v7.0.0
|
||||
* The version of the punycode module bundled in Node.js is being deprecated.
|
||||
* In a future major version of Node.js this module will be removed.
|
||||
* Users currently depending on the punycode module should switch to using
|
||||
* the userland-provided Punycode.js module instead.
|
||||
*/
|
||||
function toUnicode(domain: string): string;
|
||||
/**
|
||||
* @deprecated since v7.0.0
|
||||
* The version of the punycode module bundled in Node.js is being deprecated.
|
||||
* In a future major version of Node.js this module will be removed.
|
||||
* Users currently depending on the punycode module should switch to using
|
||||
* the userland-provided Punycode.js module instead.
|
||||
*/
|
||||
function toASCII(domain: string): string;
|
||||
/**
|
||||
* @deprecated since v7.0.0
|
||||
* The version of the punycode module bundled in Node.js is being deprecated.
|
||||
* In a future major version of Node.js this module will be removed.
|
||||
* Users currently depending on the punycode module should switch to using
|
||||
* the userland-provided Punycode.js module instead.
|
||||
*/
|
||||
const ucs2: ucs2;
|
||||
interface ucs2 {
|
||||
/**
|
||||
* @deprecated since v7.0.0
|
||||
* The version of the punycode module bundled in Node.js is being deprecated.
|
||||
* In a future major version of Node.js this module will be removed.
|
||||
* Users currently depending on the punycode module should switch to using
|
||||
* the userland-provided Punycode.js module instead.
|
||||
*/
|
||||
decode(string: string): number[];
|
||||
/**
|
||||
* @deprecated since v7.0.0
|
||||
* The version of the punycode module bundled in Node.js is being deprecated.
|
||||
* In a future major version of Node.js this module will be removed.
|
||||
* Users currently depending on the punycode module should switch to using
|
||||
* the userland-provided Punycode.js module instead.
|
||||
*/
|
||||
encode(codePoints: ReadonlyArray<number>): string;
|
||||
}
|
||||
/**
|
||||
* @deprecated since v7.0.0
|
||||
* The version of the punycode module bundled in Node.js is being deprecated.
|
||||
* In a future major version of Node.js this module will be removed.
|
||||
* Users currently depending on the punycode module should switch to using
|
||||
* the userland-provided Punycode.js module instead.
|
||||
*/
|
||||
const version: string;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2018 Made With MOXY Lda <hello@moxy.studio>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
@@ -0,0 +1,216 @@
|
||||
/**
|
||||
* @fileoverview Rule to warn about using dot notation instead of square bracket notation when possible.
|
||||
* @author Josh Perez
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Requirements
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
const astUtils = require("./utils/ast-utils");
|
||||
const keywords = require("./utils/keywords");
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Rule Definition
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
const validIdentifier = /^[a-zA-Z_$][\w$]*$/u;
|
||||
|
||||
// `null` literal must be handled separately.
|
||||
const literalTypesToCheck = new Set(["string", "boolean"]);
|
||||
|
||||
/** @type {import('../types').Rule.RuleModule} */
|
||||
module.exports = {
|
||||
meta: {
|
||||
type: "suggestion",
|
||||
|
||||
defaultOptions: [
|
||||
{
|
||||
allowKeywords: true,
|
||||
allowPattern: "",
|
||||
},
|
||||
],
|
||||
|
||||
docs: {
|
||||
description: "Enforce dot notation whenever possible",
|
||||
recommended: false,
|
||||
frozen: true,
|
||||
url: "https://eslint.org/docs/latest/rules/dot-notation",
|
||||
},
|
||||
|
||||
schema: [
|
||||
{
|
||||
type: "object",
|
||||
properties: {
|
||||
allowKeywords: {
|
||||
type: "boolean",
|
||||
},
|
||||
allowPattern: {
|
||||
type: "string",
|
||||
},
|
||||
},
|
||||
additionalProperties: false,
|
||||
},
|
||||
],
|
||||
|
||||
fixable: "code",
|
||||
|
||||
messages: {
|
||||
useDot: "[{{key}}] is better written in dot notation.",
|
||||
useBrackets: ".{{key}} is a syntax error.",
|
||||
},
|
||||
},
|
||||
|
||||
create(context) {
|
||||
const [options] = context.options;
|
||||
const allowKeywords = options.allowKeywords;
|
||||
const sourceCode = context.sourceCode;
|
||||
|
||||
let allowPattern;
|
||||
|
||||
if (options.allowPattern) {
|
||||
allowPattern = new RegExp(options.allowPattern, "u");
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the property is valid dot notation
|
||||
* @param {ASTNode} node The dot notation node
|
||||
* @param {string|boolean|null} value Value which is to be checked
|
||||
* @returns {void}
|
||||
*/
|
||||
function checkComputedProperty(node, value) {
|
||||
if (
|
||||
validIdentifier.test(value) &&
|
||||
(allowKeywords || !keywords.includes(String(value))) &&
|
||||
!(allowPattern && allowPattern.test(value))
|
||||
) {
|
||||
const formattedValue =
|
||||
node.property.type === "Literal"
|
||||
? JSON.stringify(value)
|
||||
: `\`${value}\``;
|
||||
|
||||
context.report({
|
||||
node: node.property,
|
||||
messageId: "useDot",
|
||||
data: {
|
||||
key: formattedValue,
|
||||
},
|
||||
*fix(fixer) {
|
||||
const leftBracket = sourceCode.getTokenAfter(
|
||||
node.object,
|
||||
astUtils.isOpeningBracketToken,
|
||||
);
|
||||
const rightBracket = sourceCode.getLastToken(node);
|
||||
const nextToken = sourceCode.getTokenAfter(node);
|
||||
|
||||
// Don't perform any fixes if there are comments inside the brackets.
|
||||
if (
|
||||
sourceCode.commentsExistBetween(
|
||||
leftBracket,
|
||||
rightBracket,
|
||||
)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Replace the brackets by an identifier.
|
||||
if (!node.optional) {
|
||||
yield fixer.insertTextBefore(
|
||||
leftBracket,
|
||||
astUtils.isDecimalInteger(node.object)
|
||||
? " ."
|
||||
: ".",
|
||||
);
|
||||
}
|
||||
yield fixer.replaceTextRange(
|
||||
[leftBracket.range[0], rightBracket.range[1]],
|
||||
String(value),
|
||||
);
|
||||
|
||||
// Insert a space after the property if it will be connected to the next token.
|
||||
if (
|
||||
nextToken &&
|
||||
rightBracket.range[1] === nextToken.range[0] &&
|
||||
!astUtils.canTokensBeAdjacent(
|
||||
String(value),
|
||||
nextToken,
|
||||
)
|
||||
) {
|
||||
yield fixer.insertTextAfter(node, " ");
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
MemberExpression(node) {
|
||||
if (
|
||||
node.computed &&
|
||||
node.property.type === "Literal" &&
|
||||
(literalTypesToCheck.has(typeof node.property.value) ||
|
||||
astUtils.isNullLiteral(node.property))
|
||||
) {
|
||||
checkComputedProperty(node, node.property.value);
|
||||
}
|
||||
if (
|
||||
node.computed &&
|
||||
astUtils.isStaticTemplateLiteral(node.property)
|
||||
) {
|
||||
checkComputedProperty(
|
||||
node,
|
||||
node.property.quasis[0].value.cooked,
|
||||
);
|
||||
}
|
||||
if (
|
||||
!allowKeywords &&
|
||||
!node.computed &&
|
||||
node.property.type === "Identifier" &&
|
||||
keywords.includes(String(node.property.name))
|
||||
) {
|
||||
context.report({
|
||||
node: node.property,
|
||||
messageId: "useBrackets",
|
||||
data: {
|
||||
key: node.property.name,
|
||||
},
|
||||
*fix(fixer) {
|
||||
const dotToken = sourceCode.getTokenBefore(
|
||||
node.property,
|
||||
);
|
||||
|
||||
// A statement that starts with `let[` is parsed as a destructuring variable declaration, not a MemberExpression.
|
||||
if (
|
||||
node.object.type === "Identifier" &&
|
||||
node.object.name === "let" &&
|
||||
!node.optional
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Don't perform any fixes if there are comments between the dot and the property name.
|
||||
if (
|
||||
sourceCode.commentsExistBetween(
|
||||
dotToken,
|
||||
node.property,
|
||||
)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Replace the identifier to brackets.
|
||||
if (!node.optional) {
|
||||
yield fixer.remove(dotToken);
|
||||
}
|
||||
yield fixer.replaceText(
|
||||
node.property,
|
||||
`["${node.property.name}"]`,
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"p521.d.ts","sourceRoot":"","sources":["../src/p521.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,sEAAsE;AACtE,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAe,IAAI,IAAI,KAAK,EAAE,MAAM,WAAW,CAAC;AACvD,sEAAsE;AACtE,eAAO,MAAM,IAAI,EAAE,OAAO,KAAa,CAAC;AACxC,sEAAsE;AACtE,eAAO,MAAM,SAAS,EAAE,OAAO,KAAa,CAAC;AAC7C,6EAA6E;AAC7E,eAAO,MAAM,WAAW,EAAE,SAAS,CAAC,MAAM,CAAqD,CAAC;AAChG,6EAA6E;AAC7E,eAAO,MAAM,aAAa,EAAE,SAAS,CAAC,MAAM,CAAuD,CAAC"}
|
||||
@@ -0,0 +1,14 @@
|
||||
function _object_without_properties_loose(source, excluded) {
|
||||
if (source == null) return {};
|
||||
|
||||
var target = {}, sourceKeys = Object.getOwnPropertyNames(source), key, i;
|
||||
for (i = 0; i < sourceKeys.length; i++) {
|
||||
key = sourceKeys[i];
|
||||
if (excluded.indexOf(key) >= 0) continue;
|
||||
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
||||
target[key] = source[key];
|
||||
}
|
||||
|
||||
return target;
|
||||
}
|
||||
export { _object_without_properties_loose as _ };
|
||||
Reference in New Issue
Block a user