Registry / testing / eslint-plugin-taro

eslint-plugin-taro

JSON →
library4.2.0jsnpmunverified

ESLint plugin providing Taro-specific linting rules for Taro multi-platform applications. Current version is 4.2.0, released alongside Taro 4.x. It enforces best practices for Taro's React-like JSX syntax and prevents platform-specific issues. Key differentiator: built for Taro's compile-time JSX transformation, with rules unavailable in standard React ESLint plugins. Release cadence follows Taro's major versions. Requires ESLint 8.x and @babel/eslint-parser 7.24.1+.

npm install eslint-plugin-taro
INSTALL
IMPORT
SIG · ESLINT-PLUGIN-TARO
E
eslint-plugin-taro
testingjavascriptv4.2.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

eslint-plugin-taro
import taro from 'eslint-plugin-taro'
const taro = require('eslint-plugin-taro')
ESM-compatible; CommonJS require also works but ESM is preferred for modern builds.
plugin:taro/recommended
extends: ['plugin:taro/recommended']
extends: ['eslint-plugin-taro/recommended']
Use the preset directly via 'plugin:'. Do not specify full package path.
rules
rules: { 'taro/no-spread-in-props': 'error' }
rules: { 'no-spread-in-props': 'error' }
All rule names must be prefixed with 'taro/' to avoid collisions.

Basic ESLint config for Taro 4+ projects: uses @babel/eslint-parser, enables recommended rules, and adds two custom rules.

// .eslintrc.cjs module.exports = { root: true, env: { browser: true, es2020: true }, extends: ['eslint:recommended', 'plugin:taro/recommended'], parser: '@babel/eslint-parser', parserOptions: { requireConfigFile: false, babelOptions: { presets: [['babel-preset-taro', { framework: 'react' }]] } }, plugins: ['taro'], rules: { 'taro/no-spread-in-props': 'error', 'taro/manipulate-jsx-as-array': 'warn' } };
Debug
Known issues
breakingFrom Taro 4, @babel/eslint-parser is required (replaced babel-eslint). Not updating breaks parsing.
fix
Install @babel/eslint-parser and set parser to '@babel/eslint-parser' in ESLint config.
affects: >=4.0.0
breakingTaro 4 requires ESLint 8.x; ESLint 9 not supported. Using ESLint 9 causes parsing errors.
fix
Downgrade to ESLint 8 manually: npm install eslint@8.
affects: >=4.0.0
breakingTaro 3 to Taro 4 migration: some rule names changed (e.g., 'no-spread-in-props' -> 'taro/no-spread-in-props').
fix
Update rule names to include 'taro/' prefix. Check changelog for all renamed rules.
affects: >=4.0.0
deprecatedRule 'taro/no-stateless-function' removed in v4; use ESLint built-in 'react/prefer-stateless-function' instead.
fix
Replace with ESLint plugin-react rule.
affects: >=4.0.0
gotchaThe parser option 'requireConfigFile: false' must be set; otherwise @babel/eslint-parser expects a Babel config file.
fix
Set parserOptions: { requireConfigFile: false } as shown in quickstart.
affects: *
Errors
Common errors & fixes
Error: Failed to load plugin 'taro' declared in '.eslintrc': Cannot find module 'eslint-plugin-taro'
Plugin not installed or ESLint cannot resolve the module.
fix
Run npm install eslint-plugin-taro --save-dev and ensure node_modules contains it.
Parsing error: The keyword 'import' is reserved
ESLint parser is not set to @babel/eslint-parser; default Espree cannot parse Taro JSX syntax.
fix
Set 'parser': '@babel/eslint-parser' in ESLint config.
Remove this '...' spread on JSX props (taro/no-spread-in-props)
Taro does not support JSX spread attributes; rule caught it.
fix
Explicitly pass all props without spread, or disable rule if intentional.
'taro' is not defined (no-undef)
Taro global variable is not recognized by ESLint.
fix
Add 'globals': { 'taro': 'writable' } to ESLint config.
Upgrade
Version history
4.2.0latest on npm
Audit
Dependencies
eslintrequiredpeer dependency; plugin requires ESLint to run
@babel/eslint-parserrequiredpeer dependency; required for parsing Taro's JSX syntax (since Taro 4)
Agent activity
2 hits · last 30 days
node
2
Resources
eslint-plugin-taro — npm install eslint-plugin-taro · libregistry