ESLint Plugin Use Macros
raw JSON → 4.0.1 verified Sat Apr 25 auth: no javascript
ESLint plugin that enforces the use of babel macros for specific libraries like styled-components and graphql-tag. Version 4.0.1, released as part of the frolint monorepo. Primarily used to automatically detect and correct imports from styled-components and graphql-tag to their macro equivalents. Differentiator: simple, focused rules for a common refactoring pattern; maintained by Wantedly.
Common errors
error ESLint couldn't find the plugin "eslint-plugin-use-macros" ↓
cause Plugin not installed or not correctly referenced in config
fix
npm install eslint-plugin-use-macros --save-dev and ensure it is listed in plugins array
error Error: Plugin 'use-macros' was not found ↓
cause Using require() in an ESM context or missing default export
fix
Use dynamic import or switch to flat config with import
error A plugin is trying to access options, but flat config doesn't support it ↓
cause Attempting to pass options to use-macros rules
fix
Remove options; rules only accept severity: 'error' or 'warn'
Warnings
breaking ESM-only since version 4.0.0 ↓
fix Use import syntax instead of require(). Ensure your project is configured to support ES modules.
gotcha Place the plugin before other plugins in the plugins array to avoid conflicts ↓
fix List 'use-macros' first in the plugins array in flat config.
gotcha Rule options are not supported; all rules are binary (error/warn/off) ↓
fix Use only 'error' or 'warn' as severity; do not pass options object.
deprecated Legacy config (.eslintrc) is deprecated and may be removed in future versions ↓
fix Migrate to flat config as shown in the README.
Install
npm install eslint-plugin-use-macros yarn add eslint-plugin-use-macros pnpm add eslint-plugin-use-macros Imports
- default wrong
const useMacros = require('eslint-plugin-use-macros')correctimport useMacros from 'eslint-plugin-use-macros' - rules wrong
const { rules } = require('eslint-plugin-use-macros')correctimport { rules } from 'eslint-plugin-use-macros' - configs
import { configs } from 'eslint-plugin-use-macros'
Quickstart
import pluginUseMacros from 'eslint-plugin-use-macros';
export default [
{
plugins: {
'use-macros': pluginUseMacros,
},
rules: {
'use-macros/styled-components': 'error',
'use-macros/graphql-tag': 'error',
},
},
];