<commit_before>/* global describe, it */

import 'should';
import yaml from 'js-yaml';
import eslintSpecialParser from '../../src/special/eslint';

const testCases = [
  {
    name: 'ignore when user not extends any config in `.eslintrc`',
    content: {},
    expected: [],
  },
  {
    name: 'ignore when `airbnb` is not used `.eslintrc`',
    content: {
      extends: 'others',
    },
    expected: [],
  },
  {
    name: 'handle the `airbnb` config',
    content: {
      extends: 'airbnb',
    },
    expected: [
      'eslint-config-airbnb',
      'eslint-plugin-react',
    ],
  },
  {
    name: 'handle the `airbnb/base` config',
    content: {
      extends: 'airbnb/base',
    },
    expected: [
      'eslint-config-airbnb',
    ],
  },
  {
    name: 'handle the `airbnb/legacy` config',
    content: {
      extends: 'airbnb/legacy',
    },
    expected: [
      'eslint-config-airbnb',
    ],
  },
  {
    name: 'detect `airbnb` even multiple configs are used',
    content: {
      extends: ['airbnb', 'others'],
    },
    expected: [
      'eslint-config-airbnb',
      'eslint-plugin-react',
    ],
  },
];

describe('eslint special parser', () => {
  it('should ignore when filename is not `.eslintrc`', () => {
    const result = eslintSpecialParser('content', '/a/file');
    result.should.deepEqual([]);
  });

  describe('with JSON format', () =>
    testCases.forEach(testCase =>
      it(`should ${testCase.name}`, () => {
        const content = JSON.stringify(testCase.content);
        const result = eslintSpecialParser(content, '/path/to/.eslintrc');
        result.should.deepEqual(testCase.expected);
      })));

  describe('with YAML format', () =>
    testCases.forEach(testCase =><commit_msg>Add test case about handling invalid format in eslintrc file.<commit_after>/* global describe, it */

import 'should';
import yaml from 'js-yaml';
import eslintSpecialParser from '../../src/special/eslint';

const testCases = [
  {
    name: 'ignore when user not extends any config in `.eslintrc`',
    content: {},
    expected: [],
  },
  {
    name: 'ignore when `airbnb` is not used `.eslintrc`',
    content: {
      extends: 'others',
    },
    expected: [],
  },
  {
    name: 'handle the `airbnb` config',
    content: {
      extends: 'airbnb',
    },
    expected: [
      'eslint-config-airbnb',
      'eslint-plugin-react',
    ],
  },
  {
    name: 'handle the `airbnb/base` config',
    content: {
      extends: 'airbnb/base',
    },
    expected: [
      'eslint-config-airbnb',
    ],
  },
  {
    name: 'handle the `airbnb/legacy` config',
    content: {
      extends: 'airbnb/legacy',
    },
    expected: [
      'eslint-config-airbnb',
    ],
  },
  {
    name: 'detect `airbnb` even multiple configs are used',
    content: {
      extends: ['airbnb', 'others'],
    },
    expected: [
      'eslint-config-airbnb',
      'eslint-plugin-react',
    ],
  },
];

describe('eslint special parser', () => {
  it('should ignore when filename is not `.eslintrc`', () => {
    const result = eslintSpecialParser('content', '/a/file');
    result.should.deepEqual([]);
  });

  it(`should handle parse error`, () => {
    const content = '{ this is an invalid JSON string';
    const result = eslintSpecialParser(content, '/path/to/.eslintrc');
    result.should.deepEqual([]);
  });

  describe('with JSON format', () =>
    testCases.forEach(testCase =>
      it(`should ${testCase.name}`, () => {
        const content = JSON.stringify(testCase.content);
        const result = eslintSpecialParser(content, '/path/to/.eslintrc');
        result.should.deepEqual(testCase.expected);
      })));

  describe('with YAML format', () =>
    testCases.forEach(testCase =>
{'fraction_non_alphanumeric': 0.1723673579315917, 'fraction_numerical': 0.0, 'mean_word_length': 2.6198830409356724, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 18, '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': '3182639', 'n_tokens_mistral': 1244, 'n_tokens_neox': 1234, 'n_words': 264}