korbit-ai[bot] commented on code in PR #32571: URL: https://github.com/apache/superset/pull/32571#discussion_r1987845850
########## superset-frontend/eslint-rules/eslint-plugin-icons/index.js: ########## @@ -0,0 +1,92 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/** + * @fileoverview Rule to warn about direct imports from @ant-design/icons + * @author Apache + */ + +//------------------------------------------------------------------------------ +// Rule Definition +//------------------------------------------------------------------------------ + +/** @type {import('eslint').Rule.RuleModule} */ +module.exports = { + rules: { + 'no-direct-ant-icons-import': { + meta: { + type: 'problem', + docs: { + description: + 'Warn when importing icons directly from @ant-design/icons', + category: 'Best Practices', + }, + schema: [], + }, + create(context) { + return { + ImportDeclaration(node) { + if (node.source.value.startsWith('@ant-design/icons')) { + context.report({ + node, + message: + "Avoid importing icons directly from '@ant-design/icons'. Use the src/components/Icons component instead.", + }); + } + }, + }; + }, + }, + 'no-fa-icons-usage': { + meta: { + type: 'problem', + docs: { + description: + 'Disallow the usage of FontAwesome icons in the codebase', + category: 'Best Practices', + }, + schema: [], + }, + create(context) { + return { + // Check for JSX elements with class names containing "fa" + JSXElement(node) { + if ( + node.openingElement && + node.openingElement.name.name === 'i' && + node.openingElement.attributes && + node.openingElement.attributes.some( + attr => + attr.name && + attr.name.name === 'className' && + /fa fa-/.test(attr.value.value), + ) + ) { Review Comment: ### Inflexible Icon Detection Strategy <sub></sub> <details> <summary>Tell me more</summary> ###### What is the issue? The FontAwesome icon detection logic is tightly coupled with a specific DOM structure and class naming pattern. ###### Why this matters This rigid implementation makes it difficult to adapt to changes in FontAwesome's implementation or to support alternative icon usage patterns. ###### Suggested change ∙ *Feature Preview* Abstract the detection logic into a configurable pattern matcher: ```javascript const createIconDetector = (config) => ({ pattern: config.pattern, test: (node) => config.matcher(node), }); ``` </details> <sub> [](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/354853ef-9b98-4116-b57d-358649b1365d?suggestedFixEnabled=true) 💬 Looking for more details? Reply to this comment to chat with Korbit. </sub> <!--- korbi internal id:96527dd4-9ae0-4235-84b0-10b1af8c1c9d --> -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
