@pobammer-ts/small-rules 2.2.0 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +7 -1
- package/dist/index.js +34 -32
- package/package.json +2 -1
package/dist/index.d.ts
CHANGED
|
@@ -379,9 +379,15 @@ declare const smallRules: import("oxlint-plugin-utilities").Plugin<{
|
|
|
379
379
|
}], "noRecursive", undefined>;
|
|
380
380
|
"no-redundant-aspect-ratio-constraint": import("oxlint-plugin-utilities").CreateRule<readonly [], "redundantAspectRatioConstraint", undefined>;
|
|
381
381
|
"no-render-helper-functions": import("oxlint-plugin-utilities").CreateRule<readonly [], "noRenderHelper", undefined>;
|
|
382
|
-
"no-restricted-property-assignment": import("oxlint-plugin-utilities").
|
|
382
|
+
"no-restricted-property-assignment": import("oxlint-plugin-utilities").CreateRule<readonly [{
|
|
383
383
|
readonly additionalProperties: false;
|
|
384
384
|
readonly properties: {
|
|
385
|
+
readonly allowFiles: {
|
|
386
|
+
readonly items: {
|
|
387
|
+
readonly type: "string";
|
|
388
|
+
};
|
|
389
|
+
readonly type: "array";
|
|
390
|
+
};
|
|
385
391
|
readonly checkComputed: {
|
|
386
392
|
readonly default: true;
|
|
387
393
|
readonly type: "boolean";
|
package/dist/index.js
CHANGED
|
@@ -5,6 +5,7 @@ import { parseSync } from "oxc-parser";
|
|
|
5
5
|
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
6
6
|
import { ResolverFactory } from "oxc-resolver";
|
|
7
7
|
import { type } from "arktype";
|
|
8
|
+
import { minimatch } from "minimatch";
|
|
8
9
|
//#region src/rules/array-type-generic.ts
|
|
9
10
|
function toGenericArrayType(typeNode, sourceCode) {
|
|
10
11
|
if (typeNode.type === "TSParenthesizedType") return toGenericArrayType(typeNode.typeAnnotation, sourceCode);
|
|
@@ -5804,30 +5805,38 @@ const noRenderHelperFunctions = defineRule({
|
|
|
5804
5805
|
});
|
|
5805
5806
|
//#endregion
|
|
5806
5807
|
//#region src/rules/no-restricted-property-assignment.ts
|
|
5807
|
-
|
|
5808
|
-
|
|
5809
|
-
|
|
5810
|
-
|
|
5811
|
-
|
|
5812
|
-
|
|
5813
|
-
|
|
5814
|
-
|
|
5815
|
-
|
|
5816
|
-
|
|
5817
|
-
|
|
5818
|
-
|
|
5819
|
-
|
|
5820
|
-
|
|
5821
|
-
|
|
5808
|
+
const isRestriction = type({
|
|
5809
|
+
"message?": "string | undefined",
|
|
5810
|
+
object: "string",
|
|
5811
|
+
properties: type("string[]").readonly()
|
|
5812
|
+
}).readonly();
|
|
5813
|
+
const isRuleOptions = type({
|
|
5814
|
+
"allowFiles?": type("string[]").readonly().or("undefined"),
|
|
5815
|
+
"checkComputed?": "boolean | undefined",
|
|
5816
|
+
restrictions: isRestriction.array().readonly()
|
|
5817
|
+
}).readonly();
|
|
5818
|
+
const MATCH_BASE = { matchBase: true };
|
|
5819
|
+
function getEffectiveOptions(context) {
|
|
5820
|
+
const [options] = context.options;
|
|
5821
|
+
if (!isRuleOptions.allows(options)) return {
|
|
5822
|
+
checkComputed: true,
|
|
5823
|
+
isAllowedFile: false,
|
|
5824
|
+
restrictions: []
|
|
5825
|
+
};
|
|
5826
|
+
const { allowFiles, checkComputed, restrictions } = options;
|
|
5827
|
+
const isAllowedFile = allowFiles?.some((pattern) => minimatch(context.filename, pattern, MATCH_BASE)) ?? false;
|
|
5828
|
+
return {
|
|
5829
|
+
checkComputed: checkComputed ?? true,
|
|
5830
|
+
isAllowedFile,
|
|
5831
|
+
restrictions
|
|
5832
|
+
};
|
|
5822
5833
|
}
|
|
5823
5834
|
const noRestrictedPropertyAssignment = defineRule({
|
|
5824
|
-
|
|
5825
|
-
|
|
5826
|
-
let checkComputed = true;
|
|
5835
|
+
create(context) {
|
|
5836
|
+
const { checkComputed, isAllowedFile, restrictions } = getEffectiveOptions(context);
|
|
5827
5837
|
function reportIfRestricted(node, reportNode) {
|
|
5828
|
-
if (!
|
|
5829
|
-
if (node.computed && !checkComputed) return;
|
|
5830
|
-
if (node.object.type !== "Identifier") return;
|
|
5838
|
+
if (isAllowedFile || !isMemberExpression(node)) return;
|
|
5839
|
+
if (node.computed && !checkComputed || node.object.type !== "Identifier") return;
|
|
5831
5840
|
const property = getMemberPropertyName(node);
|
|
5832
5841
|
if (property === void 0) return;
|
|
5833
5842
|
for (const restriction of restrictions) {
|
|
@@ -5854,17 +5863,6 @@ const noRestrictedPropertyAssignment = defineRule({
|
|
|
5854
5863
|
AssignmentExpression(node) {
|
|
5855
5864
|
reportIfRestricted(node.left, node);
|
|
5856
5865
|
},
|
|
5857
|
-
before() {
|
|
5858
|
-
const [options] = context.options;
|
|
5859
|
-
if (!isRuleOptions(options)) {
|
|
5860
|
-
restrictions = [];
|
|
5861
|
-
checkComputed = true;
|
|
5862
|
-
return;
|
|
5863
|
-
}
|
|
5864
|
-
const { checkComputed: nextCheckComputed, restrictions: nextRestrictions } = options;
|
|
5865
|
-
restrictions = nextRestrictions;
|
|
5866
|
-
checkComputed = nextCheckComputed ?? true;
|
|
5867
|
-
},
|
|
5868
5866
|
UpdateExpression(node) {
|
|
5869
5867
|
reportIfRestricted(node.argument, node);
|
|
5870
5868
|
}
|
|
@@ -5882,6 +5880,10 @@ const noRestrictedPropertyAssignment = defineRule({
|
|
|
5882
5880
|
schema: [{
|
|
5883
5881
|
additionalProperties: false,
|
|
5884
5882
|
properties: {
|
|
5883
|
+
allowFiles: {
|
|
5884
|
+
items: { type: "string" },
|
|
5885
|
+
type: "array"
|
|
5886
|
+
},
|
|
5885
5887
|
checkComputed: {
|
|
5886
5888
|
default: true,
|
|
5887
5889
|
type: "boolean"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pobammer-ts/small-rules",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "Various Oxlint-native rules for linting roblox-ts projects.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"lint",
|
|
@@ -70,6 +70,7 @@
|
|
|
70
70
|
"dependencies": {
|
|
71
71
|
"arktype": "2.2.1",
|
|
72
72
|
"ignore": "7.0.5",
|
|
73
|
+
"minimatch": "10.2.5",
|
|
73
74
|
"oxc-parser": "0.138.0",
|
|
74
75
|
"oxc-resolver": "11.21.3",
|
|
75
76
|
"oxlint-plugin-utilities": "1.1.0"
|