Skip to content

Commit

Permalink
feat(eslint-plugin-patternfly-react): update rules for eslint v9 (#10743
Browse files Browse the repository at this point in the history
)
  • Loading branch information
kmcfaul authored Jul 16, 2024
1 parent 98cd2fb commit c88b15d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ module.exports = {
]
},
create(context) {
const sourceCode = context.sourceCode ?? context.getSourceCode();
const [importMap = {}] = context.options;
return {
ImportDeclaration(node) {
const defaultImport = node.specifiers.find(spec => spec.type === 'ImportDefaultSpecifier');
const defaultImport = node.specifiers.find((spec) => spec.type === 'ImportDefaultSpecifier');
if (!defaultImport) {
return;
}
Expand All @@ -33,9 +34,11 @@ module.exports = {
received: receivedName
},
fix(fixer) {
const [varDecl] = context.getDeclaredVariables(node);
const [varDecl] = sourceCode.getDeclaredVariables
? sourceCode.getDeclaredVariables(node, fixer)
: context.getDeclaredVariables();
return [
...varDecl.references.map(ref => fixer.replaceText(ref.identifier, expectedName)),
...varDecl.references.map((ref) => fixer.replaceText(ref.identifier, expectedName)),
fixer.replaceText(defaultImport, expectedName)
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module.exports = {
]
},
create(context) {
const sourceCode = context.sourceCode ?? context.getSourceCode();
return {
ExportNamedDeclaration(node) {
if (!node.declaration) {
Expand All @@ -39,12 +40,11 @@ module.exports = {
typeAnnotation.typeAnnotation.typeName.left.name === 'React' &&
['FunctionComponent', 'FC', 'SFC'].includes(typeAnnotation.typeAnnotation.typeName.right.name)
) {
const displayNameNode = context
.getSourceCode()
.ast.body.filter(n => n.type === 'ExpressionStatement')
.filter(n => n.expression.left)
const displayNameNode = sourceCode.ast.body
.filter((n) => n.type === 'ExpressionStatement')
.filter((n) => n.expression.left)
.find(
n => n.expression.left.object.name === displayName && n.expression.left.property.name === 'displayName'
(n) => n.expression.left.object.name === displayName && n.expression.left.property.name === 'displayName'
);
if (!displayNameNode) {
context.report({
Expand All @@ -64,7 +64,7 @@ module.exports = {
declaration.superClass.property.name === 'Component'
) {
const classBody = declaration.body.body;
const displayNameNode = classBody.find(n => n.type === 'ClassProperty' && n.key.name === 'displayName');
const displayNameNode = classBody.find((n) => n.type === 'ClassProperty' && n.key.name === 'displayName');
if (!displayNameNode) {
context.report({
node,
Expand Down

0 comments on commit c88b15d

Please sign in to comment.