index.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* eslint-env mocha */
  2. 'use strict';
  3. const plugin = require('..');
  4. const assert = require('assert');
  5. const fs = require('fs');
  6. const path = require('path');
  7. const ruleFiles = fs.readdirSync(path.resolve(__dirname, '../lib/rules/'))
  8. .map(f => path.basename(f, '.js'));
  9. describe('all rule files should be exported by the plugin', () => {
  10. ruleFiles.forEach(ruleName => {
  11. it(`should export ${ruleName}`, () => {
  12. assert.equal(
  13. plugin.rules[ruleName],
  14. require(path.join('../lib/rules', ruleName))
  15. );
  16. });
  17. });
  18. });
  19. describe('deprecated rules', () => {
  20. it('marks all deprecated rules as deprecated', () => {
  21. ruleFiles.forEach(ruleName => {
  22. const inDeprecatedRules = Boolean(plugin.deprecatedRules[ruleName]);
  23. const isDeprecated = plugin.rules[ruleName].meta.deprecated;
  24. if (inDeprecatedRules) {
  25. assert(isDeprecated, `${ruleName} metadata should mark it as deprecated`);
  26. } else {
  27. assert(!isDeprecated, `${ruleName} metadata should not mark it as deprecated`);
  28. }
  29. });
  30. });
  31. });
  32. describe('configurations', () => {
  33. it('should export a \'recommended\' configuration', () => {
  34. assert(plugin.configs.recommended);
  35. Object.keys(plugin.configs.recommended.rules).forEach(configName => {
  36. assert.equal(configName.indexOf('react/'), 0);
  37. const ruleName = configName.substring('react/'.length);
  38. assert(plugin.rules[ruleName]);
  39. });
  40. ruleFiles.forEach(ruleName => {
  41. const inRecommendedConfig = Boolean(plugin.configs.recommended.rules[`react/${ruleName}`]);
  42. const isRecommended = plugin.rules[ruleName].meta.docs.recommended;
  43. if (inRecommendedConfig) {
  44. assert(isRecommended, `${ruleName} metadata should mark it as recommended`);
  45. } else {
  46. assert(!isRecommended, `${ruleName} metadata should not mark it as recommended`);
  47. }
  48. });
  49. });
  50. it('should export a \'all\' configuration', () => {
  51. assert(plugin.configs.all);
  52. Object.keys(plugin.configs.all.rules).forEach(configName => {
  53. assert.equal(configName.indexOf('react/'), 0);
  54. assert.equal(plugin.configs.all.rules[configName], 2);
  55. });
  56. ruleFiles.forEach(ruleName => {
  57. const inDeprecatedRules = Boolean(plugin.deprecatedRules[ruleName]);
  58. const inAllConfig = Boolean(plugin.configs.all.rules[`react/${ruleName}`]);
  59. assert(inDeprecatedRules ^ inAllConfig);
  60. });
  61. });
  62. });