Skip to content

Commit

Permalink
test: show that Linter never applies schema defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaKGoldberg committed Feb 15, 2024
1 parent 73a5f06 commit 9ccaa85
Showing 1 changed file with 86 additions and 0 deletions.
86 changes: 86 additions & 0 deletions tests/lib/linter/linter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6739,6 +6739,47 @@ var a = "test2";
});
});

describe("options", () => {
it("rules should ignore schema defaults", () => {
linter.defineRule("my-rule", {
meta: {
schema: [{
default: { inSchema: "from-schema-root" },
type: "object",
properties: {
inSchema: { default: "from-schema", type: "string" }
},
additionalProperties: false
}]
},
create(context) {
return {
Program(node) {
context.report({
message: JSON.stringify(context.options[0] ?? {}),
node
});
}
};
}
});

const config = {
rules: {
"my-rule": "error"
}
};

const code = "";
const messages = linter.verify(code, config);

assert.deepStrictEqual(
JSON.parse(messages[0].message),
{}
);
});
});

describe("processors", () => {
let receivedFilenames = [];
let receivedPhysicalFilenames = [];
Expand Down Expand Up @@ -15385,6 +15426,51 @@ var a = "test2";
});
});

describe("options", () => {
it("rules should ignore schema defaults", () => {
const config = {
plugins: {
test: {
rules: {
checker: {
meta: {
schema: [{
default: { inSchema: "from-schema-root" },
type: "object",
properties: {
inSchema: { default: "from-schema", type: "string" }
},
additionalProperties: false
}]
},
create(context) {
return {
Program(node) {
context.report({
message: JSON.stringify(context.options[0] ?? {}),
node
});
}
};
}
}
}
}
},
rules: {
"test/checker": "error"
}
};

const messages = linter.verify("foo", config, filename);

assert.deepStrictEqual(
JSON.parse(messages[0].message),
{}
);
});
});

describe("processors", () => {
let receivedFilenames = [];
let receivedPhysicalFilenames = [];
Expand Down

0 comments on commit 9ccaa85

Please sign in to comment.