Skip to content

feat: updated configurations for the flat config format#47

Open
SergoDrovski wants to merge 1 commit into
theodo:masterfrom
SergoDrovski:master
Open

feat: updated configurations for the flat config format#47
SergoDrovski wants to merge 1 commit into
theodo:masterfrom
SergoDrovski:master

Conversation

@SergoDrovski

Copy link
Copy Markdown

Add ESLint 9 Support

🎯 Problem

This plugin currently doesn't work with ESLint 9 due to:

  • Incompatible plugin structure
  • Missing schema validation for rule options
  • Deprecated context.report() usage
  • Error: Value [{"trustedLibraries":["lib"]}] should NOT have more than 0 items

🚀 Solution

  • ✅ Added ESLint 9 flat config support
  • ✅ Updated plugin metadata structure
  • ✅ Added proper schema validation for rule options
  • ✅ Updated context.report() calls to object syntax
  • ✅ Maintained backward compatibility with ESLint 8
  • ✅ Added usage examples for both config formats

📋 Changes

Core Changes

  • index.js: Updated plugin structure with metadata and flat config support
  • rules/catch-potential-xss-react.js: Added schema validation and updated report calls
  • rules/catch-potential-xss-vue.js: Added schema validation and updated report calls
  • utils.js: Updated context.report() in defineTemplateBodyVisitor

Documentation

  • Updated README with ESLint 9 usage examples
  • Added flat config examples
  • Documented migration steps

🧪 Testing

Tested with:

  • ESLint 9.30.1 ✅
  • ESLint 8.57.1 ✅ (backward compatibility)
  • React projects ✅
  • Vue projects ✅

Before

Error: Key "rules": Key "risxss/catch-potential-xss-react":
Value [{"trustedLibraries":["@frontend/core/shared/lib/cleanHTML/safeHTML"]}] should NOT have more than 0 items.

After

✅ No errors, rules work correctly with options

📦 Usage Examples

ESLint 9 (Flat Config)

import risxss from 'eslint-plugin-risxss';

export default [
  {
    plugins: { risxss },
    rules: {
      'risxss/catch-potential-xss-react': ['error', {
        trustedLibraries: ['@frontend/core/shared/lib/cleanHTML/safeHTML']
      }]
    }
  }
];

ESLint 8 (Legacy Config)

module.exports = {
  plugins: ['risxss'],
  rules: {
    'risxss/catch-potential-xss-react': ['error', {
      trustedLibraries: ['@frontend/core/shared/lib/cleanHTML/safeHTML']
    }]
  }
};

🔄 Migration Guide

For users upgrading to ESLint 9:

  1. Update to flat config format
  2. Change plugin import syntax
  3. Update rule configuration (no breaking changes in options)

⚠️ Breaking Changes

None - full backward compatibility maintained.

📝 Checklist

  • Code follows project style
  • Backward compatibility maintained
  • Documentation updated
  • Manual testing completed
  • No breaking changes introduced

This PR resolves the ESLint 9 compatibility issues while maintaining full backward compatibility with ESLint 8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant