eslint-plugin-roblox-ts
Advanced tools
Comparing version 0.0.4 to 0.0.5
173
out/index.js
@@ -29,5 +29,27 @@ "use strict"; | ||
} | ||
module.exports = { | ||
const makeRule = experimental_utils_1.ESLintUtils.RuleCreator(name => name); | ||
/** We just use this for intellisense */ | ||
const makePlugin = (obj) => { | ||
const ruleNames = new Set(); | ||
const { rules, configs } = obj; | ||
for (const ruleName in rules) { | ||
ruleNames.add(ruleName); | ||
const url = rules[ruleName].meta.docs.url; | ||
if (ruleName !== url) { | ||
throw new Error(`Name mismatch in eslint-plugin-roblox-ts: ${ruleName} vs ${url}`); | ||
} | ||
} | ||
for (const configName in configs) { | ||
for (const ruleName in configs[configName].rules) { | ||
if (ruleName.startsWith("roblox-ts/") && !ruleNames.has(ruleName.slice(10))) { | ||
throw new Error(`${ruleName} is not a valid rule defined in eslint-plugin-roblox-ts! Try one of the following: ` + | ||
[...ruleNames].join(", ")); | ||
} | ||
} | ||
} | ||
return obj; | ||
}; | ||
module.exports = makePlugin({ | ||
rules: { | ||
"ban-null": experimental_utils_1.ESLintUtils.RuleCreator(name => name)({ | ||
"ban-null": makeRule({ | ||
name: "ban-null", | ||
@@ -40,2 +62,3 @@ meta: { | ||
recommended: "error", | ||
requiresTypeChecking: false, | ||
}, | ||
@@ -69,3 +92,3 @@ fixable: "code", | ||
}), | ||
"misleading-luatuple-checks": experimental_utils_1.ESLintUtils.RuleCreator(name => name)({ | ||
"misleading-luatuple-checks": makeRule({ | ||
name: "misleading-luatuple-checks", | ||
@@ -78,10 +101,5 @@ meta: { | ||
recommended: "error", | ||
requiresTypeChecking: true, | ||
}, | ||
schema: [ | ||
{ | ||
type: "object", | ||
properties: {}, | ||
additionalProperties: false, | ||
}, | ||
], | ||
schema: [], | ||
messages: { | ||
@@ -146,2 +164,123 @@ bannedLuaTupleCheck: "Unexpected LuaTuple in conditional expression. Add [0].", | ||
}), | ||
"no-for-in": makeRule({ | ||
name: "no-for-in", | ||
meta: { | ||
type: "problem", | ||
docs: { | ||
description: "Disallows iterating with a for-in loop", | ||
category: "Possible Errors", | ||
recommended: "error", | ||
requiresTypeChecking: false, | ||
}, | ||
messages: { | ||
forInViolation: "For-in loops are forbidden because it always types the iterator variable as `string`. Use for-of or array.forEach instead.", | ||
}, | ||
schema: [], | ||
fixable: "code", | ||
}, | ||
defaultOptions: [], | ||
create(context) { | ||
return { | ||
ForInStatement(node) { | ||
context.report({ | ||
node, | ||
messageId: "forInViolation", | ||
fix: fix => fix.replaceTextRange([node.left.range[1], node.right.range[0]], " of "), | ||
}); | ||
}, | ||
}; | ||
}, | ||
}), | ||
"no-delete": makeRule({ | ||
name: "no-delete", | ||
meta: { | ||
type: "problem", | ||
docs: { | ||
description: "Disallows the delete operator", | ||
category: "Possible Errors", | ||
recommended: "error", | ||
requiresTypeChecking: false, | ||
}, | ||
schema: [], | ||
messages: { | ||
deleteViolation: "The delete operator is not supported. Please use a map instead and use map.delete()", | ||
}, | ||
}, | ||
defaultOptions: [], | ||
create(context) { | ||
return { | ||
UnaryExpression(node) { | ||
if (node.operator === "delete") { | ||
context.report({ node, messageId: "deleteViolation" }); | ||
} | ||
}, | ||
}; | ||
}, | ||
}), | ||
"no-regex": makeRule({ | ||
name: "no-regex", | ||
meta: { | ||
type: "problem", | ||
docs: { | ||
description: "Disallows the regex operator", | ||
category: "Possible Errors", | ||
recommended: "error", | ||
requiresTypeChecking: false, | ||
}, | ||
schema: [], | ||
messages: { | ||
regexViolation: "Regex literals are not supported.", | ||
}, | ||
}, | ||
defaultOptions: [], | ||
create(context) { | ||
const sourceCode = context.getSourceCode(); | ||
return { | ||
Literal(node) { | ||
const token = sourceCode.getFirstToken(node); | ||
if (token && token.type === "RegularExpression") { | ||
context.report({ | ||
node, | ||
messageId: "regexViolation", | ||
}); | ||
} | ||
}, | ||
}; | ||
}, | ||
}), | ||
"no-getters-or-setters": makeRule({ | ||
name: "no-getters-or-setters", | ||
meta: { | ||
type: "problem", | ||
docs: { | ||
description: "Disallows getters and setters", | ||
category: "Possible Errors", | ||
recommended: "error", | ||
requiresTypeChecking: false, | ||
}, | ||
schema: [], | ||
messages: { | ||
getterSetterViolation: "Getters and Setters are not supported for performance reasons. Please use a normal method instead.", | ||
}, | ||
fixable: "code", | ||
}, | ||
defaultOptions: [], | ||
create(context) { | ||
function checkMethodDefinition(node, fields) { | ||
for (const prop of fields) { | ||
if ("kind" in prop && (prop.kind === "get" || prop.kind === "set")) { | ||
context.report({ | ||
node, | ||
messageId: "getterSetterViolation", | ||
fix: fix => fix.replaceTextRange([prop.range[0] + 3, prop.key.range[0]], ""), | ||
}); | ||
} | ||
} | ||
} | ||
return { | ||
ObjectExpression: node => checkMethodDefinition(node, node.properties), | ||
ClassBody: node => checkMethodDefinition(node, node.body), | ||
}; | ||
}, | ||
}), | ||
}, | ||
@@ -152,6 +291,16 @@ configs: { | ||
"roblox-ts/ban-null": "error", | ||
"roblox-ts/misleading-luatuple-checks": "warn", | ||
"roblox-ts/misleading-luatuple-checks": "error", | ||
"roblox-ts/no-for-in": "error", | ||
"roblox-ts/no-delete": "error", | ||
"roblox-ts/no-regex": "error", | ||
"roblox-ts/no-getters-or-setters": "error", | ||
"no-void": "error", | ||
"no-with": "error", | ||
"no-debugger": "error", | ||
"no-labels": "error", | ||
"prefer-rest-params": "error", | ||
eqeqeq: "error", | ||
}, | ||
}, | ||
}, | ||
}; | ||
}); |
{ | ||
"name": "eslint-plugin-roblox-ts", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"main": "out/index.js", | ||
@@ -5,0 +5,0 @@ "devDependencies": { |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
13711
300
1