<commit_before>'use strict';

const generateRuleTests = require('../../helpers/rule-test-harness');

generateRuleTests({
  name: 'no-invalid-interactive',

  config: true,

  good: [
    '<button {{action "foo"}}></button>',
    '<div role="button" {{action "foo"}}></div>',
    '<div randomProperty={{myValue}}></div>',
    '<li><button {{action "foo"}}></button></li>',
    '<form {{action "foo" on="submit"}}></form>',
    '<form onsubmit={{action "foo"}}></form>',
    '<form {{action "foo" on="reset"}}></form>',
    '<form onreset={{action "foo"}}></form>',
    '<img onerror={{action "foo"}}>',
    '<InputSearch @onInput={{action "foo"}} />',
    '<InputSearch @onInput={{action "foo"}}></InputSearch>',
    '{{#with (hash bar=(component "foo")) as |foo|}}<foo.bar @onInput={{action "foo"}}></foo.bar>{{/with}}',
    {
      config: { additionalInteractiveTags: ['div'] },
      template: '<div {{action "foo"}}></div>',
    },
    {
      config: { additionalInteractiveTags: ['div'] },
      template: '<div onclick={{action "foo"}}></div>',
    },
    {
      config: { additionalInteractiveTags: ['img'] },
      template: '<img onerror={{action "foo"}}>',
    },
  ],

  bad: [
    {
      template: '<div {{action "foo"}}></div>',

      result: {
        message: 'Interaction added to non-interactive element',
        line: 1,
        column: 5,
        source: '<div {{action "foo"}}></div>',
      },
    },

    {
      template: '<div onclick={{action "foo"}}></div>',

      result: {
        message: 'Interaction added to non-interactive element',
        line: 1,
        column: 5,
        source: '<div onclick={{action "foo"}}></div>',
      },
    },

    {
      // This example is detected solely based on the DOM event attribute name.
      template: '<div onclick={{pipe-action "foo"}}></div>',

      result: {
        message: 'Interaction added to non-interactive element',
        line: 1,
        column: 5,
        source: '<div onclick={{pipe-action "foo"}}></div>',
      },
    },

    {
      template: '<div onsubmit={{action "foo"}}></div>',

      result: {
        message: 'Interaction added to non-interactive element',
        line: 1,
        column: 5,
        source: '<div onsubmit={{action "foo"}}></div>',
      },
    },

    {
      // Any usage of the `action` helper will be caught, regardless of the attribute name.
      template: '<div randomAttribute={{action "foo"}}></div>',

      result: {
        message: 'Interaction added to non-interactive element',
        line: 1,
        column: 5,
        source: '<div randomAttribute={{action "foo"}}></div>',
      },
    },

    {
      template: '<form {{action "foo" on="click"}}></form>',

      result: {
        message: 'Interaction added to non-interactive element',
        line: 1,
        column: 6,
        source: '<form {{action "foo" on="click"}}></form>',
      },
    },

    {
      template: '<div {{action "foo" on="submit"}}></div>',

      result: {
        message: 'Interaction added to non-interactive element',
        line: 1,
        column: 5,
        source: '<div {{action "foo" on="submit"}}></div>',
      },
    },
  ],
});
<commit_msg>Test interactivity of onload for img tags<commit_after>'use strict';

const generateRuleTests = require('../../helpers/rule-test-harness');

generateRuleTests({
  name: 'no-invalid-interactive',

  config: true,

  good: [
    '<button {{action "foo"}}></button>',
    '<div role="button" {{action "foo"}}></div>',
    '<div randomProperty={{myValue}}></div>',
    '<li><button {{action "foo"}}></button></li>',
    '<form {{action "foo" on="submit"}}></form>',
    '<form onsubmit={{action "foo"}}></form>',
    '<form {{action "foo" on="reset"}}></form>',
    '<form onreset={{action "foo"}}></form>',
    '<img onerror={{action "foo"}}>',
    '<img onload={{action "foo"}}>',
    '<InputSearch @onInput={{action "foo"}} />',
    '<InputSearch @onInput={{action "foo"}}></InputSearch>',
    '{{#with (hash bar=(component "foo")) as |foo|}}<foo.bar @onInput={{action "foo"}}></foo.bar>{{/with}}',
    {
      config: { additionalInteractiveTags: ['div'] },
      template: '<div {{action "foo"}}></div>',
    },
    {
      config: { additionalInteractiveTags: ['div'] },
      template: '<div onclick={{action "foo"}}></div>',
    },
    {
      config: { additionalInteractiveTags: ['img'] },
      template: '<img onerror={{action "foo"}}>',
    },
  ],

  bad: [
    {
      template: '<div {{action "foo"}}></div>',

      result: {
        message: 'Interaction added to non-interactive element',
        line: 1,
        column: 5,
        source: '<div {{action "foo"}}></div>',
      },
    },

    {
      template: '<div onclick={{action "foo"}}></div>',

      result: {
        message: 'Interaction added to non-interactive element',
        line: 1,
        column: 5,
        source: '<div onclick={{action "foo"}}></div>',
      },
    },

    {
      // This example is detected solely based on the DOM event attribute name.
      template: '<div onclick={{pipe-action "foo"}}></div>',

      result: {
        message: 'Interaction added to non-interactive element',
        line: 1,
        column: 5,
        source: '<div onclick={{pipe-action "foo"}}></div>',
      },
    },

    {
      template: '<div onsubmit={{action "foo"}}></div>',

      result: {
        message: 'Interaction added to non-interactive element',
        line: 1,
        column: 5,
        source: '<div onsubmit={{action "foo"}}></div>',
      },
    },

    {
      // Any usage of the `action` helper will be caught, regardless of the attribute name.
      template: '<div randomAttribute={{action "foo"}}></div>',

      result: {
        message: 'Interaction added to non-interactive element',
        line: 1,
        column: 5,
        source: '<div randomAttribute={{action "foo"}}></div>',
      },
    },

    {
      template: '<form {{action "foo" on="click"}}></form>',

      result: {
        message: 'Interaction added to non-interactive element',
        line: 1,
        column: 6,
        source: '<form {{action "foo" on="click"}}></form>',
      },
    },

    {
      template: '<div {{action "foo" on="submit"}}></div>',

      result: {
        message: 'Interaction added to non-interactive element',
        line: 1,
        column: 5,
        source: '<div {{action "foo" on="submit"}}></div>',
      },
    },
  ],
});

{'fraction_non_alphanumeric': 0.21358619617596766, 'fraction_numerical': 0.004352557127312296, 'mean_word_length': 2.54295154185022, 'pattern_counts': {'":': 0, '<': 118, '<?xml version=': 0, '>': 118, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2136223', 'n_tokens_mistral': 1998, 'n_tokens_neox': 2050, 'n_words': 487}