<commit_before>import {
  devices
, hiddenFromAT
} from '../util'

const def = [
  'image'
, 'picture'
, 'photo'
]

export default [{
  tagName: 'img'
, msg: 'Redundant `alt` attribute. Screen-readers already announce `img` tags as an image. '
     + 'You don\'t need to use the words like `image`, `photo,` or `picture` in the alt prop.'
, url: 'http://webaim.org/techniques/alttext'
, affects: [
    devices.screenReaders
  ]
, test (_, props) {
    const hidden   = hiddenFromAT(props)
    const alt      = (props.alt || '').toLowerCase()
    const words    = ctx.options[0] || def
    const contains = words.reduce((a, w) => a || (alt.indexOf(w) >= 0), false)

    return hidden || !contains

  }
}]

export const fail = [{
  when: 'is a redundant alt message'
, render: React => <img src='foo' alt='bar image foo' />
}, {
  when: 'is a redundant alt message (different opts)'
, opts: [[ 'foto' ]]
, render: React => <img src='foo' alt='bar foto' />
}]

export const pass = [{
  when: 'the `alt` does not contain redundant words'
, render: React => <img src='foo' alt='nice' />
}, {
  when: 'the `alt` does not contain redundant words (different opts)'
, opts: [[ 'foto' ]]
, render: React => <img src='foo' alt='image' />
}, {
  when: 'the element is aria-hidden'
, render: React => <img src='foo' alt='nice' ariaHidden />
}]
<commit_msg>add ctx<commit_after>import {
  devices
, hiddenFromAT
} from '../util'

const def = [
  'image'
, 'picture'
, 'photo'
]

export default [{
  tagName: 'img'
, msg: 'Redundant `alt` attribute. Screen-readers already announce `img` tags as an image. '
     + 'You don\'t need to use the words like `image`, `photo,` or `picture` in the alt prop.'
, url: 'http://webaim.org/techniques/alttext'
, affects: [
    devices.screenReaders
  ]
, test (_, props, _c, ctx) {
    const hidden   = hiddenFromAT(props)
    const alt      = (props.alt || '').toLowerCase()
    const words    = ctx.options[0] || def
    const contains = words.reduce((a, w) => a || (alt.indexOf(w) >= 0), false)

    return hidden || !contains

  }
}]

export const fail = [{
  when: 'is a redundant alt message'
, render: React => <img src='foo' alt='bar image foo' />
}, {
  when: 'is a redundant alt message (different opts)'
, opts: [[ 'foto' ]]
, render: React => <img src='foo' alt='bar foto' />
}]

export const pass = [{
  when: 'the `alt` does not contain redundant words'
, render: React => <img src='foo' alt='nice' />
}, {
  when: 'the `alt` does not contain redundant words (different opts)'
, opts: [[ 'foto' ]]
, render: React => <img src='foo' alt='image' />
}, {
  when: 'the element is aria-hidden'
, render: React => <img src='foo' alt='nice' ariaHidden />
}]

{'fraction_non_alphanumeric': 0.17999256229081442, 'fraction_numerical': 0.0014875418371141688, 'mean_word_length': 3.4536423841059603, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 27, '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': '6314312', 'n_tokens_mistral': 935, 'n_tokens_neox': 912, 'n_words': 295}