Skip to content

Commit

Permalink
fix: revert TypeScript migration
Browse files Browse the repository at this point in the history
Fixes #268
Fixes #269
Fixes #270
  • Loading branch information
SimenB committed May 22, 2019
1 parent 331457d commit 1ce1402
Show file tree
Hide file tree
Showing 14 changed files with 162 additions and 441 deletions.
13 changes: 3 additions & 10 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
const { globals } = require('./').environments.globals;

module.exports = {
parser: '@typescript-eslint/parser',
extends: [
'eslint:recommended',
'plugin:eslint-plugin/recommended',
'plugin:node/recommended',
'plugin:@typescript-eslint/eslint-recommended',
'prettier',
],
plugins: ['eslint-plugin', 'node', 'prettier', '@typescript-eslint'],
plugins: ['eslint-plugin', 'node', 'prettier'],
parserOptions: {
ecmaVersion: 2017,
},
Expand Down Expand Up @@ -38,14 +37,8 @@ module.exports = {
},
overrides: [
{
files: ['*.test.js', '*.test.ts'],
files: ['*.test.js'],
globals,
},
{
files: ['*.ts'],
parserOptions: {
sourceType: 'module',
},
},
],
};
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ script:
- yarn commitlint --from="$TRAVIS_BRANCH" --to="$TRAVIS_COMMIT"
- yarn commitlint --from=$TRAVIS_COMMIT
- yarn prettylint
- yarn typecheck
- yarn test --coverage --maxWorkers 2
after_script: greenkeeper-lockfile-upload
jobs:
Expand Down
5 changes: 1 addition & 4 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
'use strict';

module.exports = {
presets: [
'@babel/preset-typescript',
['@babel/preset-env', { targets: { node: 6 } }],
],
presets: [['@babel/preset-env', { targets: { node: 6 } }]],
};
20 changes: 5 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,19 @@
"eslint": ">=5"
},
"scripts": {
"pretest": "yarn build",
"lint": "eslint . --ignore-pattern '!.eslintrc.js' --ext js,ts",
"prepare": "yarn build",
"lint": "eslint . --ignore-pattern '!.eslintrc.js'",
"prettylint": "prettylint docs/**/*.md README.md package.json",
"prepublishOnly": "yarn build",
"test": "jest",
"build": "babel --extensions .js,.ts src --out-dir lib",
"typecheck": "tsc -p ."
},
"dependencies": {
"@typescript-eslint/experimental-utils": "^1.9.1-alpha.3"
"build": "babel src --out-dir lib"
},
"devDependencies": {
"@babel/cli": "^7.4.4",
"@babel/core": "^7.4.4",
"@babel/preset-env": "^7.4.4",
"@babel/preset-typescript": "^7.3.3",
"@commitlint/cli": "^7.0.0",
"@commitlint/config-conventional": "^7.0.1",
"@types/eslint": "^4.16.6",
"@types/jest": "^24.0.12",
"@types/node": "^12.0.0",
"@typescript-eslint/eslint-plugin": "^1.9.1-alpha.3",
"babel-jest": "^24.8.0",
"eslint": "^5.1.0",
"eslint-config-prettier": "^4.1.0",
Expand All @@ -60,16 +51,15 @@
"jest-runner-eslint": "^0.7.1",
"lint-staged": "^8.0.4",
"prettier": "^1.10.2",
"prettylint": "^1.0.0",
"typescript": "^3.4.5"
"prettylint": "^1.0.0"
},
"prettier": {
"proseWrap": "always",
"singleQuote": true,
"trailingComma": "all"
},
"lint-staged": {
"*.{js,ts}": [
"*.js": [
"eslint --fix",
"git add"
],
Expand Down
20 changes: 3 additions & 17 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,12 @@
const fs = require('fs');
const path = require('path');

// copied from https://github.com/babel/babel/blob/56044c7851d583d498f919e9546caddf8f80a72f/packages/babel-helpers/src/helpers.js#L558-L562
function interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : { default: obj };
}

const rules = fs
.readdirSync(path.join(__dirname, 'rules'))
.filter(
rule => rule !== '__tests__' && rule !== 'util.js' && rule !== 'tsUtils.ts',
)
.map(rule =>
rule.endsWith('js')
? path.basename(rule, '.js')
: path.basename(rule, '.ts'),
)
.filter(rule => rule !== '__tests__' && rule !== 'util.js')
.map(rule => path.basename(rule, '.js'))
.reduce(
(acc, curr) => ({
...acc,
[curr]: interopRequireDefault(require(`./rules/${curr}`)).default,
}),
(acc, curr) => Object.assign(acc, { [curr]: require(`./rules/${curr}`) }),
{},
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
import { RuleTester as ESLintRuleTester } from 'eslint';
import { TSESLint } from '@typescript-eslint/experimental-utils';
import rule from '../lowercase-name';
'use strict';

const RuleTester: TSESLint.RuleTester = ESLintRuleTester as any;
const { RuleTester } = require('eslint');
const rule = require('../lowercase-name');

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

ruleTester.run('lowercase-name', rule, {
valid: [
'randomFunction()',
'foo.bar()',
'it()',
"it(' ', function () {})",
'it(" ", function () {})',
Expand All @@ -26,8 +22,6 @@ ruleTester.run('lowercase-name', rule, {
'it("123 foo", function () {})',
'it(42, function () {})',
'it(``)',
'it("")',
'it(42)',
'test()',
"test('foo', function () {})",
'test("foo", function () {})',
Expand All @@ -36,8 +30,6 @@ ruleTester.run('lowercase-name', rule, {
'test("123 foo", function () {})',
'test("42", function () {})',
'test(``)',
'test("")',
'test(42)',
'describe()',
"describe('foo', function () {})",
'describe("foo", function () {})',
Expand All @@ -47,8 +39,6 @@ ruleTester.run('lowercase-name', rule, {
'describe("42", function () {})',
'describe(function () {})',
'describe(``)',
'describe("")',
'describe(42)',
],

invalid: [
Expand All @@ -57,8 +47,7 @@ ruleTester.run('lowercase-name', rule, {
output: "it('foo', function () {})",
errors: [
{
messageId: 'unexpectedLowercase',
data: { method: 'it' },
message: '`it`s should begin with lowercase',
column: 1,
line: 1,
},
Expand All @@ -69,8 +58,7 @@ ruleTester.run('lowercase-name', rule, {
output: 'it("foo", function () {})',
errors: [
{
messageId: 'unexpectedLowercase',
data: { method: 'it' },
message: '`it`s should begin with lowercase',
column: 1,
line: 1,
},
Expand All @@ -81,8 +69,7 @@ ruleTester.run('lowercase-name', rule, {
output: 'it(`foo`, function () {})',
errors: [
{
messageId: 'unexpectedLowercase',
data: { method: 'it' },
message: '`it`s should begin with lowercase',
column: 1,
line: 1,
},
Expand All @@ -93,8 +80,7 @@ ruleTester.run('lowercase-name', rule, {
output: "test('foo', function () {})",
errors: [
{
messageId: 'unexpectedLowercase',
data: { method: 'test' },
message: '`test`s should begin with lowercase',
column: 1,
line: 1,
},
Expand All @@ -105,8 +91,7 @@ ruleTester.run('lowercase-name', rule, {
output: 'test("foo", function () {})',
errors: [
{
messageId: 'unexpectedLowercase',
data: { method: 'test' },
message: '`test`s should begin with lowercase',
column: 1,
line: 1,
},
Expand All @@ -117,8 +102,7 @@ ruleTester.run('lowercase-name', rule, {
output: 'test(`foo`, function () {})',
errors: [
{
messageId: 'unexpectedLowercase',
data: { method: 'test' },
message: '`test`s should begin with lowercase',
column: 1,
line: 1,
},
Expand All @@ -129,8 +113,7 @@ ruleTester.run('lowercase-name', rule, {
output: "describe('foo', function () {})",
errors: [
{
messageId: 'unexpectedLowercase',
data: { method: 'describe' },
message: '`describe`s should begin with lowercase',
column: 1,
line: 1,
},
Expand All @@ -141,8 +124,7 @@ ruleTester.run('lowercase-name', rule, {
output: 'describe("foo", function () {})',
errors: [
{
messageId: 'unexpectedLowercase',
data: { method: 'describe' },
message: '`describe`s should begin with lowercase',
column: 1,
line: 1,
},
Expand All @@ -153,8 +135,7 @@ ruleTester.run('lowercase-name', rule, {
output: 'describe(`foo`, function () {})',
errors: [
{
messageId: 'unexpectedLowercase',
data: { method: 'describe' },
message: '`describe`s should begin with lowercase',
column: 1,
line: 1,
},
Expand All @@ -165,8 +146,7 @@ ruleTester.run('lowercase-name', rule, {
output: 'describe(`some longer description`, function () {})',
errors: [
{
messageId: 'unexpectedLowercase',
data: { method: 'describe' },
message: '`describe`s should begin with lowercase',
column: 1,
line: 1,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
import { RuleTester as ESLintRuleTester } from 'eslint';
import { TSESLint } from '@typescript-eslint/experimental-utils';
import rule from '../no-jest-import';
'use strict';

const RuleTester: TSESLint.RuleTester = ESLintRuleTester as any;

const ruleTester = new RuleTester({
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 6,
},
});
const rule = require('../no-jest-import.js');
const { RuleTester } = require('eslint');
const ruleTester = new RuleTester();
const message = `Jest is automatically in scope. Do not import "jest", as Jest doesn't export anything.`;

ruleTester.run('no-jest-import', rule, {
valid: [
Expand All @@ -28,7 +22,7 @@ ruleTester.run('no-jest-import', rule, {
{
endColumn: 15,
column: 9,
messageId: 'unexpectedImport',
message,
},
],
},
Expand All @@ -38,8 +32,8 @@ ruleTester.run('no-jest-import', rule, {
errors: [
{
endColumn: 24,
column: 18,
messageId: 'unexpectedImport',
column: 1,
message,
},
],
},
Expand All @@ -49,7 +43,7 @@ ruleTester.run('no-jest-import', rule, {
{
endColumn: 26,
column: 20,
messageId: 'unexpectedImport',
message,
},
],
},
Expand All @@ -59,8 +53,8 @@ ruleTester.run('no-jest-import', rule, {
errors: [
{
endColumn: 34,
column: 28,
messageId: 'unexpectedImport',
column: 1,
message,
},
],
},
Expand All @@ -71,7 +65,7 @@ ruleTester.run('no-jest-import', rule, {
{
endColumn: 28,
column: 22,
messageId: 'unexpectedImport',
message,
},
],
},
Expand Down
Loading

0 comments on commit 1ce1402

Please sign in to comment.