Skip to content

Commit

Permalink
chore: convert to import/export (#302)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB authored Jul 17, 2019
1 parent 9f858cb commit 31c7cef
Show file tree
Hide file tree
Showing 74 changed files with 335 additions and 389 deletions.
25 changes: 17 additions & 8 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ module.exports = {
'plugin:node/recommended',
'prettier',
],
plugins: ['eslint-plugin', 'node', 'prettier'],
plugins: ['eslint-plugin', 'node', 'prettier', 'import'],
parserOptions: {
ecmaVersion: 2017,
ecmaVersion: 2018,
},
env: {
node: true,
Expand All @@ -24,21 +24,30 @@ module.exports = {
'object-shorthand': ['warn', 'always', { avoidExplicitReturnArrows: true }],
'prefer-destructuring': [
'error',
{
VariableDeclarator: {
array: true,
object: true,
},
},
{ VariableDeclarator: { array: true, object: true } },
],
'prettier/prettier': 'error',
'node/no-unsupported-features/es-syntax': 'off',
'node/no-unsupported-features/es-builtins': 'error',
'import/no-commonjs': 'error',
'import/no-unused-modules': 'error',
},
overrides: [
{
files: ['*.test.js'],
globals,
},
{
files: 'src/**/*',
parserOptions: {
sourceType: 'module',
},
},
{
files: ['.eslintrc.js', 'babel.config.js'],
rules: {
'import/no-commonjs': 'off',
},
},
],
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"eslint": "^5.1.0",
"eslint-config-prettier": "^5.1.0",
"eslint-plugin-eslint-plugin": "^2.0.0",
"eslint-plugin-import": "^2.18.0",
"eslint-plugin-node": "^8.0.0",
"eslint-plugin-prettier": "^3.0.0",
"husky": "^1.0.1",
Expand Down
12 changes: 5 additions & 7 deletions src/__tests__/rules.test.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
'use strict';

const fs = require('fs');
const path = require('path');
const { rules } = require('../');
import { existsSync } from 'fs';
import { resolve } from 'path';
import { rules } from '../';

const ruleNames = Object.keys(rules);
const numberOfRules = 33;

describe('rules', () => {
it('should have a corresponding doc for each rule', () => {
ruleNames.forEach(rule => {
const docPath = path.resolve(__dirname, '../../docs/rules', `${rule}.md`);
const docPath = resolve(__dirname, '../../docs/rules', `${rule}.md`);

if (!fs.existsSync(docPath)) {
if (!existsSync(docPath)) {
throw new Error(
`Could not find documentation file for rule "${rule}" in path "${docPath}"`,
);
Expand Down
26 changes: 17 additions & 9 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
'use strict';
import { readdirSync } from 'fs';
import { basename, join } from 'path';
import * as snapshotProcessor from './processors/snapshot-processor';

const fs = require('fs');
const path = require('path');
// copied from https://github.com/babel/babel/blob/d8da63c929f2d28c401571e2a43166678c555bc4/packages/babel-helpers/src/helpers.js#L602-L606
/* istanbul ignore next */
function interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : { default: obj };
}

const rules = fs
.readdirSync(path.join(__dirname, 'rules'))
function importDefault(moduleName) {
return interopRequireDefault(require(moduleName)).default;
}

const rules = readdirSync(join(__dirname, 'rules'))
.filter(rule => rule !== '__tests__' && rule !== 'util.js')
.map(rule => path.basename(rule, '.js'))
.map(rule => basename(rule, '.js'))
.reduce(
(acc, curr) => Object.assign(acc, { [curr]: require(`./rules/${curr}`) }),
(acc, curr) =>
Object.assign(acc, { [curr]: importDefault(`./rules/${curr}`) }),
{},
);
let allRules = {};
Object.keys(rules).forEach(function(key) {
allRules[`jest/${key}`] = 'error';
});

const snapshotProcessor = require('./processors/snapshot-processor');

// eslint-disable-next-line import/no-commonjs
module.exports = {
configs: {
all: {
Expand Down
4 changes: 1 addition & 3 deletions src/processors/__tests__/snapshot-processor.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';

const snapshotProcessor = require('../snapshot-processor');
import * as snapshotProcessor from '../snapshot-processor';

describe('snapshot-processor', () => {
it('exports an object with preprocess and postprocess functions', () => {
Expand Down
11 changes: 2 additions & 9 deletions src/processors/snapshot-processor.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
'use strict';

// https://eslint.org/docs/developer-guide/working-with-plugins#processors-in-plugins
const preprocess = source => [source];
export const preprocess = source => [source];

const postprocess = messages =>
export const postprocess = messages =>
messages[0].filter(
// snapshot files should only be linted with snapshot specific rules
message => message.ruleId === 'jest/no-large-snapshots',
);

module.exports = {
preprocess,
postprocess,
};
6 changes: 2 additions & 4 deletions src/rules/__tests__/consistent-test-it.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';

const { RuleTester } = require('eslint');
const rule = require('../consistent-test-it');
import { RuleTester } from 'eslint';
import rule from '../consistent-test-it';

const ruleTester = new RuleTester({
parserOptions: {
Expand Down
6 changes: 2 additions & 4 deletions src/rules/__tests__/expect-expect.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';

const { RuleTester } = require('eslint');
const rule = require('../expect-expect');
import { RuleTester } from 'eslint';
import rule from '../expect-expect';

const ruleTester = new RuleTester({
parserOptions: {
Expand Down
6 changes: 2 additions & 4 deletions src/rules/__tests__/lowercase-name.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';

const { RuleTester } = require('eslint');
const rule = require('../lowercase-name');
import { RuleTester } from 'eslint';
import rule from '../lowercase-name';

const ruleTester = new RuleTester({
parserOptions: {
Expand Down
6 changes: 2 additions & 4 deletions src/rules/__tests__/no-alias-methods.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';

const { RuleTester } = require('eslint');
const rule = require('../no-alias-methods');
import { RuleTester } from 'eslint';
import rule from '../no-alias-methods';

const ruleTester = new RuleTester();

Expand Down
6 changes: 2 additions & 4 deletions src/rules/__tests__/no-commented-out-tests.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';

const { RuleTester } = require('eslint');
const rule = require('../no-commented-out-tests');
import { RuleTester } from 'eslint';
import rule from '../no-commented-out-tests';

const ruleTester = new RuleTester({
parserOptions: {
Expand Down
6 changes: 2 additions & 4 deletions src/rules/__tests__/no-disabled-tests.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';

const { RuleTester } = require('eslint');
const rule = require('../no-disabled-tests');
import { RuleTester } from 'eslint';
import rule from '../no-disabled-tests';

const ruleTester = new RuleTester({
parserOptions: {
Expand Down
6 changes: 2 additions & 4 deletions src/rules/__tests__/no-duplicate-hooks.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';

const { RuleTester } = require('eslint');
const rule = require('../no-duplicate-hooks');
import { RuleTester } from 'eslint';
import rule from '../no-duplicate-hooks';

const ruleTester = new RuleTester({
parserOptions: {
Expand Down
6 changes: 2 additions & 4 deletions src/rules/__tests__/no-empty-title.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';

const { RuleTester } = require('eslint');
const rule = require('../no-empty-title');
import { RuleTester } from 'eslint';
import rule from '../no-empty-title';

const ruleTester = new RuleTester({
parserOptions: {
Expand Down
6 changes: 2 additions & 4 deletions src/rules/__tests__/no-focused-tests.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';

const { RuleTester } = require('eslint');
const rule = require('../no-focused-tests');
import { RuleTester } from 'eslint';
import rule from '../no-focused-tests';

const ruleTester = new RuleTester();

Expand Down
6 changes: 2 additions & 4 deletions src/rules/__tests__/no-hooks.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';

const { RuleTester } = require('eslint');
const rule = require('../no-hooks');
import { RuleTester } from 'eslint';
import rule from '../no-hooks';

const ruleTester = new RuleTester({
parserOptions: {
Expand Down
6 changes: 2 additions & 4 deletions src/rules/__tests__/no-identical-title.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';

const { RuleTester } = require('eslint');
const rule = require('../no-identical-title');
import { RuleTester } from 'eslint';
import rule from '../no-identical-title';

const ruleTester = new RuleTester();

Expand Down
6 changes: 2 additions & 4 deletions src/rules/__tests__/no-jasmine-globals.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';

const { RuleTester } = require('eslint');
const rule = require('../no-jasmine-globals');
import { RuleTester } from 'eslint';
import rule from '../no-jasmine-globals';

const ruleTester = new RuleTester();

Expand Down
5 changes: 2 additions & 3 deletions src/rules/__tests__/no-jest-import.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';
import { RuleTester } from 'eslint';
import rule from '../no-jest-import';

const rule = require('../no-jest-import.js');
const { RuleTester } = require('eslint');
const ruleTester = new RuleTester();

ruleTester.run('no-jest-import', rule, {
Expand Down
8 changes: 4 additions & 4 deletions src/rules/__tests__/no-large-snapshots.test.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
'use strict';
import { RuleTester } from 'eslint';
import { parse } from 'babel-eslint';
import rule from '../no-large-snapshots';

const { RuleTester } = require('eslint');
const rule = require('../no-large-snapshots');
const noLargeSnapshots = rule.create;
const { parse } = require('babel-eslint');

const ruleTester = new RuleTester({
parserOptions: {
ecmaVersion: 2015,
},
});

// lines - 1 to account for the starting newline we always add.
const generateSnapshotNode = ({ lines, title = 'a big component 1' }) =>
parse(`exports[\`${title}\`] = \`\n${'line\n'.repeat(lines - 1)}\`;`).body[0];
Expand Down
5 changes: 2 additions & 3 deletions src/rules/__tests__/no-mocks-import.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';
import { RuleTester } from 'eslint';
import rule from '../no-mocks-import';

const rule = require('../no-mocks-import.js');
const { RuleTester } = require('eslint');
const ruleTester = new RuleTester();

ruleTester.run('no-mocks-import', rule, {
Expand Down
6 changes: 2 additions & 4 deletions src/rules/__tests__/no-test-callback.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';

const { RuleTester } = require('eslint');
const rule = require('../no-test-callback');
import { RuleTester } from 'eslint';
import rule from '../no-test-callback';

const ruleTester = new RuleTester({
parserOptions: {
Expand Down
6 changes: 2 additions & 4 deletions src/rules/__tests__/no-test-prefixes.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';

const { RuleTester } = require('eslint');
const rule = require('../no-test-prefixes');
import { RuleTester } from 'eslint';
import rule from '../no-test-prefixes';

const ruleTester = new RuleTester();

Expand Down
6 changes: 2 additions & 4 deletions src/rules/__tests__/no-test-return-statement.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';

const { RuleTester } = require('eslint');
const rule = require('../no-test-return-statement');
import { RuleTester } from 'eslint';
import rule from '../no-test-return-statement';

const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2015 } });

Expand Down
6 changes: 2 additions & 4 deletions src/rules/__tests__/no-truthy-falsy.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';

const { RuleTester } = require('eslint');
const rule = require('../no-truthy-falsy');
import { RuleTester } from 'eslint';
import rule from '../no-truthy-falsy';

const ruleTester = new RuleTester();

Expand Down
6 changes: 2 additions & 4 deletions src/rules/__tests__/prefer-called-with.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';

const { RuleTester } = require('eslint');
const rule = require('../prefer-called-with');
import { RuleTester } from 'eslint';
import rule from '../prefer-called-with';

const ruleTester = new RuleTester();

Expand Down
6 changes: 2 additions & 4 deletions src/rules/__tests__/prefer-expect-assertions.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';

const { RuleTester } = require('eslint');
const rule = require('../prefer-expect-assertions');
import { RuleTester } from 'eslint';
import rule from '../prefer-expect-assertions';

const ruleTester = new RuleTester({
parserOptions: {
Expand Down
6 changes: 2 additions & 4 deletions src/rules/__tests__/prefer-inline-snapshots.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';

const { RuleTester } = require('eslint');
const rule = require('../prefer-inline-snapshots');
import { RuleTester } from 'eslint';
import rule from '../prefer-inline-snapshots';

const ruleTester = new RuleTester();

Expand Down
6 changes: 2 additions & 4 deletions src/rules/__tests__/prefer-spy-on.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';

const { RuleTester } = require('eslint');
const rule = require('../prefer-spy-on');
import { RuleTester } from 'eslint';
import rule from '../prefer-spy-on';

const ruleTester = new RuleTester({
parserOptions: {
Expand Down
6 changes: 2 additions & 4 deletions src/rules/__tests__/prefer-strict-equal.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';

const { RuleTester } = require('eslint');
const rule = require('../prefer-strict-equal');
import { RuleTester } from 'eslint';
import rule from '../prefer-strict-equal';

const ruleTester = new RuleTester();

Expand Down
Loading

0 comments on commit 31c7cef

Please sign in to comment.