Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@reverecre/eslint-plugin-fontawesome

Package Overview
Dependencies
Maintainers
2
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@reverecre/eslint-plugin-fontawesome - npm Package Compare versions

Comparing version 1.2.1 to 1.2.2

87

lib/rules/shakeable-imports.js

@@ -31,2 +31,10 @@ /**

//----------------------------------------------------------------------
// Variables
//----------------------------------------------------------------------
const isTypeScript = context.parserPath.includes(
'node_modules/@typescript-eslint/parser'
);
//----------------------------------------------------------------------
// Helpers

@@ -37,13 +45,41 @@ //----------------------------------------------------------------------

function generateFixedImports(node) {
const importedIcons = node.specifiers.map((spec) => {
if (spec.type !== 'ImportSpecifier') {
return null;
}
const nonIconImports = node.specifiers
.filter((spec) => {
return (
spec.type === 'ImportSpecifier' &&
!spec.imported.name.startsWith('fa')
);
})
.map((spec) => {
if (spec.type !== 'ImportSpecifier') {
return null;
}
return `import { ${spec.imported.name}${
spec.imported.name !== spec.local.name ? ` as ${spec.local.name}` : ''
} } from '${node.source.value}/${spec.imported.name}';`;
});
return `import ${isTypeScript ? 'type ' : ''}{ ${spec.imported.name}${
spec.imported.name !== spec.local.name
? ` as ${spec.local.name}`
: ''
} } from '${node.source.value}';`;
});
return importedIcons.filter(Boolean).join('\n');
const importedIcons = node.specifiers
.filter((spec) => {
return (
spec.type === 'ImportSpecifier' &&
spec.imported.name.startsWith('fa')
);
})
.map((spec) => {
if (spec.type !== 'ImportSpecifier') {
return null;
}
return `import { ${spec.imported.name}${
spec.imported.name !== spec.local.name
? ` as ${spec.local.name}`
: ''
} } from '${node.source.value}/${spec.imported.name}';`;
});
return [...nonIconImports, ...importedIcons].filter(Boolean).join('\n');
}

@@ -60,15 +96,24 @@

if (node.source.value.match(/^@fortawesome\/[\w-]+-icons$/g)) {
context.report({
node,
messageId: 'badImport',
fix: (fixer) => fixer.replaceText(node, generateFixedImports(node)),
suggest: [
{
messageId: 'fixImport',
fix: (fixer) => {
return fixer.replaceText(node, generateFixedImports(node));
const hasIconImport = node.specifiers.some(
(spec) =>
spec.type === 'ImportSpecifier' &&
spec.imported.name.startsWith('fa')
);
if (hasIconImport) {
context.report({
node,
messageId: 'badImport',
fix: (fixer) =>
fixer.replaceText(node, generateFixedImports(node)),
suggest: [
{
messageId: 'fixImport',
fix: (fixer) => {
return fixer.replaceText(node, generateFixedImports(node));
},
},
},
],
});
],
});
}
}

@@ -75,0 +120,0 @@ },

{
"name": "@reverecre/eslint-plugin-fontawesome",
"version": "1.2.1",
"version": "1.2.2",
"description": "Ensures proper usage of Font Awesome imports",

@@ -5,0 +5,0 @@ "keywords": [

@@ -83,2 +83,36 @@ /* eslint-disable node/no-unpublished-require */

{
parserOptions: { ecmaVersion: 2022, sourceType: 'module' },
code: `import { IconDefinition, faCoffee as coffeeIcon } from '@fortawesome/free-solid-svg-icons';`,
output: `import { IconDefinition } from '@fortawesome/free-solid-svg-icons';
import { faCoffee as coffeeIcon } from '@fortawesome/free-solid-svg-icons/faCoffee';`,
errors: [
{
messageId: 'badImport',
suggestions: [
{
output: `import { IconDefinition } from '@fortawesome/free-solid-svg-icons';
import { faCoffee as coffeeIcon } from '@fortawesome/free-solid-svg-icons/faCoffee';`,
},
],
},
],
},
{
parserOptions: { ecmaVersion: 2022, sourceType: 'module' },
code: `import { IconDefinition as def, faCoffee as coffeeIcon } from '@fortawesome/free-solid-svg-icons';`,
output: `import { IconDefinition as def } from '@fortawesome/free-solid-svg-icons';
import { faCoffee as coffeeIcon } from '@fortawesome/free-solid-svg-icons/faCoffee';`,
errors: [
{
messageId: 'badImport',
suggestions: [
{
output: `import { IconDefinition as def } from '@fortawesome/free-solid-svg-icons';
import { faCoffee as coffeeIcon } from '@fortawesome/free-solid-svg-icons/faCoffee';`,
},
],
},
],
},
{
parser: require.resolve('@typescript-eslint/parser'),

@@ -128,3 +162,37 @@ code: `import { faCoffee } from '@fortawesome/free-solid-svg-icons';`,

},
{
parser: require.resolve('@typescript-eslint/parser'),
code: `import { IconDefinition, faCoffee as coffeeIcon } from '@fortawesome/free-solid-svg-icons';`,
output: `import type { IconDefinition } from '@fortawesome/free-solid-svg-icons';
import { faCoffee as coffeeIcon } from '@fortawesome/free-solid-svg-icons/faCoffee';`,
errors: [
{
messageId: 'badImport',
suggestions: [
{
output: `import type { IconDefinition } from '@fortawesome/free-solid-svg-icons';
import { faCoffee as coffeeIcon } from '@fortawesome/free-solid-svg-icons/faCoffee';`,
},
],
},
],
},
{
parser: require.resolve('@typescript-eslint/parser'),
code: `import { IconDefinition as def, faCoffee as coffeeIcon } from '@fortawesome/free-solid-svg-icons';`,
output: `import type { IconDefinition as def } from '@fortawesome/free-solid-svg-icons';
import { faCoffee as coffeeIcon } from '@fortawesome/free-solid-svg-icons/faCoffee';`,
errors: [
{
messageId: 'badImport',
suggestions: [
{
output: `import type { IconDefinition as def } from '@fortawesome/free-solid-svg-icons';
import { faCoffee as coffeeIcon } from '@fortawesome/free-solid-svg-icons/faCoffee';`,
},
],
},
],
},
],
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc