index.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. /**
  20. * @fileoverview Rule to warn about direct imports from @ant-design/icons
  21. * @author Apache
  22. */
  23. //------------------------------------------------------------------------------
  24. // Rule Definition
  25. //------------------------------------------------------------------------------
  26. /** @type {import('eslint').Rule.RuleModule} */
  27. module.exports = {
  28. rules: {
  29. 'no-fa-icons-usage': {
  30. meta: {
  31. type: 'problem',
  32. docs: {
  33. description:
  34. 'Disallow the usage of FontAwesome icons in the codebase',
  35. category: 'Best Practices',
  36. },
  37. schema: [],
  38. },
  39. create(context) {
  40. return {
  41. // Check for JSX elements with class names containing "fa"
  42. JSXElement(node) {
  43. if (
  44. node.openingElement &&
  45. node.openingElement.name.name === 'i' &&
  46. node.openingElement.attributes &&
  47. node.openingElement.attributes.some(
  48. attr =>
  49. attr.name &&
  50. attr.name.name === 'className' &&
  51. /fa fa-/.test(attr.value.value),
  52. )
  53. ) {
  54. context.report({
  55. node,
  56. message:
  57. 'FontAwesome icons should not be used. Use the src/components/Icons component instead.',
  58. });
  59. }
  60. },
  61. };
  62. },
  63. },
  64. },
  65. };