Skip to content
Permalink
Browse files
chore: port lowercase-name to TypeScript (#258)
  • Loading branch information
SimenB committed May 12, 2019
1 parent 3df0058 commit ca2aa277d48f0bf8ccf66803b84a6301afece00d
@@ -3,13 +3,14 @@
const { globals } = require('./').environments.globals;

module.exports = {
parser: '@typescript-eslint/parser',
extends: [
'eslint:recommended',
'plugin:eslint-plugin/recommended',
'plugin:node/recommended',
'plugin:@typescript-eslint/eslintRecommended',
'prettier',
],
plugins: ['eslint-plugin', 'node', 'prettier'],
plugins: ['eslint-plugin', 'node', 'prettier', '@typescript-eslint'],
parserOptions: {
ecmaVersion: 2017,
},
@@ -37,8 +38,14 @@ module.exports = {
},
overrides: [
{
files: ['*.test.js'],
files: ['*.test.js', '*.test.ts'],
globals,
},
{
files: ['*.ts'],
parserOptions: {
sourceType: 'module',
},
},
],
};
@@ -14,6 +14,7 @@ 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:
@@ -1,5 +1,8 @@
'use strict';

module.exports = {
presets: [['@babel/preset-env', { targets: { node: 6 } }]],
presets: [
'@babel/preset-typescript',
['@babel/preset-env', { targets: { node: 6 } }],
],
};
@@ -28,18 +28,25 @@
},
"scripts": {
"postinstall": "yarn build",
"lint": "eslint . --ignore-pattern '!.eslintrc.js'",
"lint": "eslint . --ignore-pattern '!.eslintrc.js' --ext js,ts",
"prettylint": "prettylint docs/**/*.md README.md package.json",
"prepublishOnly": "yarn build",
"test": "jest",
"build": "babel src --out-dir lib"
"build": "babel --extensions .js,.ts src --out-dir lib",
"typecheck": "tsc -p ."
},
"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.8.0",
"@typescript-eslint/experimental-utils": "^1.8.0",
"babel-jest": "^24.8.0",
"eslint": "^5.1.0",
"eslint-config-prettier": "^4.1.0",
@@ -51,15 +58,16 @@
"jest-runner-eslint": "^0.7.1",
"lint-staged": "^8.0.4",
"prettier": "^1.10.2",
"prettylint": "^1.0.0"
"prettylint": "^1.0.0",
"typescript": "^3.4.5"
},
"prettier": {
"proseWrap": "always",
"singleQuote": true,
"trailingComma": "all"
},
"lint-staged": {
"*.js": [
"*.{js,ts}": [
"eslint --fix",
"git add"
],
@@ -3,12 +3,26 @@
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')
.map(rule => path.basename(rule, '.js'))
.filter(
rule => rule !== '__tests__' && rule !== 'util.js' && rule !== 'tsUtils.ts',
)
.map(rule =>
rule.endsWith('js')
? path.basename(rule, '.js')
: path.basename(rule, '.ts'),
)
.reduce(
(acc, curr) => Object.assign(acc, { [curr]: require(`./rules/${curr}`) }),
(acc, curr) => ({
...acc,
[curr]: interopRequireDefault(require(`./rules/${curr}`)).default,
}),
{},
);

@@ -1,16 +1,20 @@
'use strict';
import { RuleTester as ESLintRuleTester } from 'eslint';
import { TSESLint } from '@typescript-eslint/experimental-utils';
import rule from '../lowercase-name';

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

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 () {})',
@@ -22,6 +26,8 @@ ruleTester.run('lowercase-name', rule, {
'it("123 foo", function () {})',
'it(42, function () {})',
'it(``)',
'it("")',
'it(42)',
'test()',
"test('foo', function () {})",
'test("foo", function () {})',
@@ -30,6 +36,8 @@ ruleTester.run('lowercase-name', rule, {
'test("123 foo", function () {})',
'test("42", function () {})',
'test(``)',
'test("")',
'test(42)',
'describe()',
"describe('foo', function () {})",
'describe("foo", function () {})',
@@ -39,6 +47,8 @@ ruleTester.run('lowercase-name', rule, {
'describe("42", function () {})',
'describe(function () {})',
'describe(``)',
'describe("")',
'describe(42)',
],

invalid: [
@@ -47,7 +57,8 @@ ruleTester.run('lowercase-name', rule, {
output: "it('foo', function () {})",
errors: [
{
message: '`it`s should begin with lowercase',
messageId: 'unexpectedLowercase',
data: { method: 'it' },
column: 1,
line: 1,
},
@@ -58,7 +69,8 @@ ruleTester.run('lowercase-name', rule, {
output: 'it("foo", function () {})',
errors: [
{
message: '`it`s should begin with lowercase',
messageId: 'unexpectedLowercase',
data: { method: 'it' },
column: 1,
line: 1,
},
@@ -69,7 +81,8 @@ ruleTester.run('lowercase-name', rule, {
output: 'it(`foo`, function () {})',
errors: [
{
message: '`it`s should begin with lowercase',
messageId: 'unexpectedLowercase',
data: { method: 'it' },
column: 1,
line: 1,
},
@@ -80,7 +93,8 @@ ruleTester.run('lowercase-name', rule, {
output: "test('foo', function () {})",
errors: [
{
message: '`test`s should begin with lowercase',
messageId: 'unexpectedLowercase',
data: { method: 'test' },
column: 1,
line: 1,
},
@@ -91,7 +105,8 @@ ruleTester.run('lowercase-name', rule, {
output: 'test("foo", function () {})',
errors: [
{
message: '`test`s should begin with lowercase',
messageId: 'unexpectedLowercase',
data: { method: 'test' },
column: 1,
line: 1,
},
@@ -102,7 +117,8 @@ ruleTester.run('lowercase-name', rule, {
output: 'test(`foo`, function () {})',
errors: [
{
message: '`test`s should begin with lowercase',
messageId: 'unexpectedLowercase',
data: { method: 'test' },
column: 1,
line: 1,
},
@@ -113,7 +129,8 @@ ruleTester.run('lowercase-name', rule, {
output: "describe('foo', function () {})",
errors: [
{
message: '`describe`s should begin with lowercase',
messageId: 'unexpectedLowercase',
data: { method: 'describe' },
column: 1,
line: 1,
},
@@ -124,7 +141,8 @@ ruleTester.run('lowercase-name', rule, {
output: 'describe("foo", function () {})',
errors: [
{
message: '`describe`s should begin with lowercase',
messageId: 'unexpectedLowercase',
data: { method: 'describe' },
column: 1,
line: 1,
},
@@ -135,7 +153,8 @@ ruleTester.run('lowercase-name', rule, {
output: 'describe(`foo`, function () {})',
errors: [
{
message: '`describe`s should begin with lowercase',
messageId: 'unexpectedLowercase',
data: { method: 'describe' },
column: 1,
line: 1,
},
@@ -146,7 +165,8 @@ ruleTester.run('lowercase-name', rule, {
output: 'describe(`some longer description`, function () {})',
errors: [
{
message: '`describe`s should begin with lowercase',
messageId: 'unexpectedLowercase',
data: { method: 'describe' },
column: 1,
line: 1,
},

This file was deleted.

0 comments on commit ca2aa27

Please sign in to comment.