Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[New] support eslint v9 #3759

Merged
merged 7 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/node-18+.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
matrix:
node-version: ${{ fromJson(needs.matrix.outputs.latest) }}
eslint:
- 9
- 8
- 7
- 6
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/node-pretest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ jobs:
name: 'nvm install lts/* && npm install'
with:
node-version: 'lts/*'
env:
NPM_CONFIG_LEGACY_PEER_DEPS: true
- run: npm run pretest

posttest:
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
## Unreleased

### Added
* support eslint v9 ([#3759][] @mdjermanovic)
* export flat configs from plugin root and fix flat config crash ([#3694][] @bradzacher @mdjermanovic)
* add [`jsx-props-no-spread-multi`] ([#3724][] @SimonSchick)

[#3759]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3759
[#3724]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3724
[#3694]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3694

### Fixed
* [`no-invalid-html-attribute`]: substitute placeholders in suggestion messages ([#3759][] @mdjermanovic)

## [7.34.4] - 2024.07.13

### Fixed
Expand Down
157 changes: 64 additions & 93 deletions lib/rules/no-invalid-html-attribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
const matchAll = require('string.prototype.matchall');
const docsUrl = require('../util/docsUrl');
const report = require('../util/report');
const getMessageData = require('../util/message');

// ------------------------------------------------------------------------------
// Rule Definition
Expand Down Expand Up @@ -224,6 +223,7 @@ const COMPONENT_ATTRIBUTE_MAP = new Map([
['rel', new Set(['link', 'a', 'area', 'form'])],
]);

/* eslint-disable eslint-plugin/no-unused-message-ids -- false positives, these messageIds are used */
const messages = {
emptyIsMeaningless: 'An empty “{{attributeName}}” attribute is meaningless.',
neverValid: '“{{reportingValue}}” is never a valid “{{attributeName}}” attribute value.',
Expand Down Expand Up @@ -264,15 +264,11 @@ function checkLiteralValueNode(context, attributeName, node, parentNode, parentN
report(context, messages.onlyStrings, 'onlyStrings', {
node,
data,
suggest: [
Object.assign(
getMessageData('suggestRemoveNonString', messages.suggestRemoveNonString),
{
data,
fix(fixer) { return fixer.remove(parentNode); },
}
),
],
suggest: [{
messageId: 'suggestRemoveNonString',
data,
fix(fixer) { return fixer.remove(parentNode); },
}],
});
return;
}
Expand All @@ -283,15 +279,11 @@ function checkLiteralValueNode(context, attributeName, node, parentNode, parentN
report(context, messages.noEmpty, 'noEmpty', {
node,
data,
suggest: [
Object.assign(
getMessageData('suggestRemoveEmpty', messages.suggestRemoveEmpty),
{
data,
fix(fixer) { return fixer.remove(node.parent); },
}
),
],
suggest: [{
messageId: 'suggestRemoveEmpty',
data,
fix(fixer) { return fixer.remove(node.parent); },
}],
});
return;
}
Expand All @@ -307,18 +299,16 @@ function checkLiteralValueNode(context, attributeName, node, parentNode, parentN
reportingValue,
};

const suggest = [{
messageId: 'suggestRemoveInvalid',
data,
fix(fixer) { return fixer.removeRange(singlePart.range); },
}];

report(context, messages.neverValid, 'neverValid', {
node,
data,
suggest: [
Object.assign(
getMessageData('suggestRemoveInvalid', messages.suggestRemoveInvalid),
{
data,
fix(fixer) { return fixer.removeRange(singlePart.range); },
}
),
],
suggest,
});
} else if (!allowedTags.has(parentNodeName)) {
const data = {
Expand All @@ -327,18 +317,16 @@ function checkLiteralValueNode(context, attributeName, node, parentNode, parentN
elementName: parentNodeName,
};

const suggest = [{
messageId: 'suggestRemoveInvalid',
data,
fix(fixer) { return fixer.removeRange(singlePart.range); },
}];

report(context, messages.notValidFor, 'notValidFor', {
node,
data,
suggest: [
Object.assign(
getMessageData('suggestRemoveInvalid', messages.suggestRemoveInvalid),
{
data,
fix(fixer) { return fixer.removeRange(singlePart.range); },
}
),
],
suggest,
});
}
}
Expand Down Expand Up @@ -375,33 +363,27 @@ function checkLiteralValueNode(context, attributeName, node, parentNode, parentN

const whitespaceParts = splitIntoRangedParts(node, /(\s+)/g);
for (const whitespacePart of whitespaceParts) {
const data = { attributeName };

if (whitespacePart.range[0] === (node.range[0] + 1) || whitespacePart.range[1] === (node.range[1] - 1)) {
report(context, messages.spaceDelimited, 'spaceDelimited', {
node,
data: { attributeName },
suggest: [
Object.assign(
getMessageData('suggestRemoveWhitespaces', messages.suggestRemoveWhitespaces),
{
data: { attributeName },
fix(fixer) { return fixer.removeRange(whitespacePart.range); },
}
),
],
data,
suggest: [{
messageId: 'suggestRemoveWhitespaces',
data,
fix(fixer) { return fixer.removeRange(whitespacePart.range); },
}],
});
} else if (whitespacePart.value !== '\u0020') {
report(context, messages.spaceDelimited, 'spaceDelimited', {
node,
data: { attributeName },
suggest: [
Object.assign(
getMessageData('suggestRemoveWhitespaces', messages.suggestRemoveWhitespaces),
{
data: { attributeName },
fix(fixer) { return fixer.replaceTextRange(whitespacePart.range, '\u0020'); },
}
),
],
data,
suggest: [{
messageId: 'suggestRemoveWhitespaces',
data,
fix(fixer) { return fixer.replaceTextRange(whitespacePart.range, '\u0020'); },
}],
});
}
}
Expand All @@ -426,15 +408,11 @@ function checkAttribute(context, node) {
report(context, messages.onlyMeaningfulFor, 'onlyMeaningfulFor', {
node: node.name,
data,
suggest: [
Object.assign(
getMessageData('suggestRemoveDefault', messages.suggestRemoveDefault),
{
data,
fix(fixer) { return fixer.remove(node); },
}
),
],
suggest: [{
messageId: 'suggestRemoveDefault',
data,
fix(fixer) { return fixer.remove(node); },
}],
});
return;
}
Expand All @@ -447,12 +425,11 @@ function checkAttribute(context, node) {
report(context, messages.emptyIsMeaningless, 'emptyIsMeaningless', {
node: node.name,
data,
suggest: [
Object.assign(
getMessageData('suggestRemoveEmpty', messages.suggestRemoveEmpty),
{ data, fix }
),
],
suggest: [{
messageId: 'suggestRemoveEmpty',
data,
fix,
}],
});
return;
}
Expand All @@ -475,25 +452,23 @@ function checkAttribute(context, node) {
report(context, messages.onlyStrings, 'onlyStrings', {
node: node.value,
data,
suggest: [
Object.assign(
getMessageData('suggestRemoveDefault', messages.suggestRemoveDefault),
{ data, fix }
),
],
suggest: [{
messageId: 'suggestRemoveDefault',
data,
fix,
}],
});
} else if (node.value.expression.type === 'Identifier' && node.value.expression.name === 'undefined') {
const data = { attributeName: attribute };

report(context, messages.onlyStrings, 'onlyStrings', {
node: node.value,
data,
suggest: [
Object.assign(
getMessageData('suggestRemoveDefault', messages.suggestRemoveDefault),
{ data, fix }
),
],
suggest: [{
messageId: 'suggestRemoveDefault',
data,
fix,
}],
});
}
}
Expand Down Expand Up @@ -523,15 +498,11 @@ function checkPropValidValue(context, node, value, attribute) {
report(context, messages.neverValid, 'neverValid', {
node: value,
data,
suggest: [
Object.assign(
getMessageData('suggestRemoveInvalid', messages.suggestRemoveInvalid),
{
data,
fix(fixer) { return fixer.replaceText(value, value.raw.replace(value.value, '')); },
}
),
],
suggest: [{
messageId: 'suggestRemoveInvalid',
data,
fix(fixer) { return fixer.replaceText(value, value.raw.replace(value.value, '')); },
}],
});
} else if (!validTagSet.has(node.arguments[0].value)) {
report(context, messages.notValidFor, 'notValidFor', {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"@typescript-eslint/parser": "^2.34.0 || ^3.10.1 || ^4.0.0 || ^5.0.0",
"aud": "^2.0.4",
"babel-eslint": "^8 || ^9 || ^10.1.0",
"eslint": "^3 || ^4 || ^5 || ^6 || ^7 || ^8",
"eslint": "^3 || ^4 || ^5 || ^6 || ^7 || ^8 || ^9",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-doc-generator": "^1.7.1",
"eslint-plugin-eslint-plugin": "^2.3.0 || ^3.5.3 || ^4.0.1 || ^5.0.5",
Expand All @@ -79,7 +79,7 @@
"typescript-eslint-parser": "^20.1.1"
},
"peerDependencies": {
"eslint": "^3 || ^4 || ^5 || ^6 || ^7 || ^8"
"eslint": "^3 || ^4 || ^5 || ^6 || ^7 || ^8 || ^9"
},
"engines": {
"node": ">=4"
Expand Down
11 changes: 11 additions & 0 deletions tests/helpers/getRuleDefiner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

const eslint = require('eslint');

// `ruleTester` is a RuleTester instance
const getRuleDefiner = (ruleTester) => (typeof Symbol !== 'undefined' && Symbol.for && ruleTester[Symbol.for('react.RuleTester.RuleDefiner')])
|| ruleTester.linter
|| eslint.linter
|| eslint.Linter;

module.exports = getRuleDefiner;
2 changes: 1 addition & 1 deletion tests/helpers/parsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ const parsers = {
&& {
errors: testObject.errors.map(
(errorObject) => {
const nextSuggestions = errorObject.suggestions && {
const nextSuggestions = errorObject.suggestions && typeof errorObject.suggestions !== 'number' && {
ljharb marked this conversation as resolved.
Show resolved Hide resolved
suggestions: errorObject.suggestions.map((suggestion) => Object.assign({}, suggestion, {
output: suggestion.output + extraComment,
})),
Expand Down
Loading