Skip to content

Commit

Permalink
chore: update RuleTester configs
Browse files Browse the repository at this point in the history
  • Loading branch information
mainframev committed Aug 23, 2024
1 parent 40f1acf commit 8594e22
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 26 deletions.
31 changes: 14 additions & 17 deletions packages/eslint-plugin/src/rules/ban-context-export/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,40 @@ const { RuleTester } = require('@typescript-eslint/rule-tester');
const path = require('path');
const rule = require('./index');

const ruleTester = new RuleTester({
parser: '@typescript-eslint/parser',
parserOptions: {
project: path.resolve(__dirname, './fixtures/ban-context-export/tsconfig.json'),
tsconfigRootDir: path.resolve(__dirname, './fixtures/ban-context-export'),
},
});
const ruleTester = new RuleTester();

/**
* @param {string} fixtureName
*/
function getParserOptions(fixtureName) {
return {
project: path.resolve(__dirname, `./fixtures/${fixtureName}/tsconfig.json`),
tsconfigRootDir: path.resolve(__dirname, `./fixtures/${fixtureName}`),
parserOptions: {
parser: '@typescript-eslint/parser',
project: path.resolve(__dirname, `./fixtures/${fixtureName}/tsconfig.json`),
tsconfigRootDir: path.resolve(__dirname, `./fixtures/${fixtureName}`),
},
};
}

ruleTester.run('ban-context-export', rule, {
valid: [
{
parserOptions: getParserOptions('internal-export'),
languageOptions: getParserOptions('internal-export'),
code: `
export { MyContext } from './context'
`,
filename: 'src/internal/index.ts',
},
{
parserOptions: getParserOptions('not-a-context'),
languageOptions: getParserOptions('not-a-context'),
code: `
export { MyContext } from './context'
`,
filename: 'src/index.ts',
},
{
options: [{ exclude: ['**/special-path/**/*'] }],
parserOptions: getParserOptions('exclude'),
languageOptions: getParserOptions('exclude'),
code: `
import * as React from 'react';
export const MyContext = React.createContext({});
Expand All @@ -50,23 +47,23 @@ ruleTester.run('ban-context-export', rule, {
invalid: [
{
errors: [{ messageId: 'nativeContext' }],
parserOptions: getParserOptions('export-specifier'),
languageOptions: getParserOptions('export-specifier'),
code: `
export { MyContext } from './context'
`,
filename: 'src/index.ts',
},
{
errors: [{ messageId: 'contextSelector' }],
parserOptions: getParserOptions('context-selector'),
languageOptions: getParserOptions('context-selector'),
code: `
export { MyContext } from './context'
`,
filename: 'src/index.ts',
},
{
errors: [{ messageId: 'nativeContext' }],
parserOptions: getParserOptions('named-export'),
languageOptions: getParserOptions('named-export'),
code: `
import * as React from 'react';
export const MyContext = React.createContext({});
Expand All @@ -75,7 +72,7 @@ ruleTester.run('ban-context-export', rule, {
},
{
errors: [{ messageId: 'contextSelector' }],
parserOptions: getParserOptions('named-export'),
languageOptions: getParserOptions('named-export'),
code: `
import { createContext } from '@fluentui/react-context-selector';
export const MyContext = createContext({});
Expand All @@ -85,7 +82,7 @@ ruleTester.run('ban-context-export', rule, {
{
errors: [{ messageId: 'nativeContext' }],
options: [{ exclude: ['**/wrong-path/**/*'] }],
parserOptions: getParserOptions('exclude'),
languageOptions: getParserOptions('exclude'),
code: `
import * as React from 'react';
export const MyContext = React.createContext({});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
const { RuleTester } = require('@typescript-eslint/rule-tester');
const rule = require('./index');

const ruleTester = new RuleTester({
parser: '@typescript-eslint/parser',
});
const ruleTester = new RuleTester();

ruleTester.run('ban-instanceof-htmlelement', rule, {
valid: [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
const { RuleTester } = require('@typescript-eslint/rule-tester');
const rule = require('./index');

const ruleTester = new RuleTester({
parser: '@typescript-eslint/parser',
});
const ruleTester = new RuleTester();

ruleTester.run('no-context-default-value', rule, {
valid: [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
const { RuleTester } = require('@typescript-eslint/rule-tester');
const rule = require('./index');

const ruleTester = new RuleTester({
parser: '@typescript-eslint/parser',
});
const ruleTester = new RuleTester();

ruleTester.run('no-restricted-imports', rule, {
valid: [
Expand Down

0 comments on commit 8594e22

Please sign in to comment.