Skip to content

Commit

Permalink
Deprecate tslint in favour of eslint (#28)
Browse files Browse the repository at this point in the history
* test: set up eslint, remove tslint and format all files

* test(.eslintignore): add .nyc_output and coverage directories
  • Loading branch information
gfmio authored Apr 29, 2020
1 parent 0a32bbe commit 19270d4
Show file tree
Hide file tree
Showing 16 changed files with 997 additions and 150 deletions.
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.nyc_output
coverage
dist
node_modules
48 changes: 48 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"plugins": ["@typescript-eslint", "eslint-comments", "mocha", "promise", "unicorn"],
"extends": [
"eslint:recommended",
"airbnb-typescript/base",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"plugin:eslint-comments/recommended",
"plugin:mocha/recommended",
"plugin:promise/recommended",
"plugin:unicorn/recommended",
"prettier",
"prettier/react",
"prettier/@typescript-eslint"
],
"env": {
"node": true,
"browser": true,
"mocha": true
},
"parserOptions": {
"project": "tsconfig.json",
"createDefaultProgram": true,
"ecmaVersion": 2020,
"sourceType": "module"
},
"rules": {
"no-use-before-define": ["error", { "functions": false, "classes": true, "variables": true }],
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/no-use-before-define": [
"error",
{ "functions": false, "classes": true, "variables": true, "typedefs": true }
],
"react/destructuring-assignment": "off",
"react/jsx-filename-extension": "off",
// Common abbreviations are known and readable
"unicorn/prevent-abbreviations": "off",
"unicorn/filename-case": [
"error",
{
"cases": {
"camelCase": true,
"pascalCase": true
}
}
]
}
}
4 changes: 2 additions & 2 deletions .prettierrc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ printWidth = 80
proseWrap = "always"
requirePragma = false
semi = true
singleQuote = false
singleQuote = true
tabWidth = 2
trailingComma = "all"

Expand All @@ -19,4 +19,4 @@ tabWidth = 2
[[overrides]]
files = "*.md"
[overrides.options]
proseWrap = "never"
proseWrap = "preserve"
2 changes: 0 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
{
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll.tslint": true,
"source.fixAll.eslint": true
},
"markdownlint.config": {
"list-marker-space": false,
"no-inline-html": false
},
"typescript.tsdk": "node_modules/typescript/lib"
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ The module content will be available as the UMD global `exampleCalculator`.
The package provides a calculator class.

```ts
import Calculator from "example-calculator";
import Calculator from 'example-calculator';
const calculator = new Calculator();
```

Expand Down Expand Up @@ -275,12 +275,12 @@ calculator.clear().inverse().value();
You can also import some operations as standalone functions from their submodules:

```ts
import add from "example-calculator/add";
import sub from "example-calculator/sub";
import mul from "example-calculator/mul";
import div from "example-calculator/div";
import mod from "example-calculator/mod";
import ln from "example-calculator/ln";
import add from 'example-calculator/add';
import sub from 'example-calculator/sub';
import mul from 'example-calculator/mul';
import div from 'example-calculator/div';
import mod from 'example-calculator/mod';
import ln from 'example-calculator/ln';

console.log(add(1, 1));
// Prints 2
Expand Down
25 changes: 21 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
"posttest:print": "nyc report",
"posttest:lcov": "nyc report --reporter=lcov",
"posttest:json": "nyc report --reporter=json",
"lint": "tslint --project tsconfig.json",
"lint": "eslint './**/*.?(js|jsx|ts|tsx)'",
"lint:fix": "eslint './**/*.?(js|jsx|ts|tsx)' --fix",
"docs": "typedoc",
"clean:dist": "rimraf ./dist ./.rpt2_cache",
"clean:node_modules": "rimraf ./node_modules",
Expand All @@ -71,11 +72,27 @@
"@types/chai": "^4.2.11",
"@types/mocha": "^7.0.2",
"@types/prettier": "^2.0.0",
"@typescript-eslint/eslint-plugin": "^2.30.0",
"@typescript-eslint/parser": "^2.30.0",
"chai": "^4.2.0",
"codecov": "^3.6.5",
"commitizen": "^4.0.4",
"cross-env": "^7.0.2",
"cz-conventional-changelog": "^3.1.0",
"eslint": "^6.8.0",
"eslint-config-airbnb-typescript": "^7.2.1",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-eslint-comments": "^3.1.2",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-mocha": "^6.3.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.1.3",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-react": "^7.19.0",
"eslint-plugin-react-hooks": "^3.0.0",
"eslint-plugin-sort-imports-es6-autofix": "^0.5.0",
"eslint-plugin-unicorn": "^19.0.1",
"gh-pages": "^2.2.0",
"husky": "^4.2.5",
"mocha": "^7.1.2",
Expand All @@ -89,7 +106,6 @@
"ts-node": "^8.9.1",
"ts-pkg-scripts": "^0.2.1",
"tslib": "^1.11.1",
"tslint": "^6.1.2",
"typedoc": "^0.17.6",
"typescript": "^3.8.3"
},
Expand Down Expand Up @@ -139,5 +155,6 @@
}
]
]
}
}
},
"dependencies": {}
}
53 changes: 22 additions & 31 deletions src/Calculator.spec.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,30 @@
import { expect } from "chai";
import { describe, it } from "mocha";
import { describe, it } from 'mocha';
import { expect } from 'chai';

import Calculator from "./Calculator";
import Calculator from './Calculator';

describe("Calculator", () => {
it("has the correct initial value when no argument is supplied", () => expect(new Calculator().value()).equal(0));
it("has the correct initial value when an argument is supplied", () => expect(new Calculator(3).value()).equal(3));
describe('Calculator', () => {
it('has the correct initial value when no argument is supplied', () => expect(new Calculator().value()).equal(0));
it('has the correct initial value when an argument is supplied', () => expect(new Calculator(3).value()).equal(3));

const calculator = new Calculator();

it("can add", () => expect(calculator.add(2).value()).equal(2));
it("can sub", () => expect(calculator.sub(1).value()).equal(1));
it("can mul", () => expect(calculator.mul(12).value()).equal(12));
it("can div", () => expect(calculator.div(2).value()).equal(6));
it("can mod", () => expect(calculator.mod(4).value()).equal(2));
// prettier-ignore
it("can exp", () => expect(calculator.sub(1).exp().value()).equal(Math.E));
it("can ln", () => expect(calculator.ln().value()).equal(1));
it("can clear", () => expect(calculator.clear().value()).equal(0));
it('can add', () => expect(calculator.add(2).value()).equal(2));
it('can sub', () => expect(calculator.sub(1).value()).equal(1));
it('can mul', () => expect(calculator.mul(12).value()).equal(12));
it('can div', () => expect(calculator.div(2).value()).equal(6));
it('can mod', () => expect(calculator.mod(4).value()).equal(2));
it('can exp', () => expect(calculator.sub(1).exp().value()).equal(Math.E));
it('can ln', () => expect(calculator.ln().value()).equal(1));
it('can clear', () => expect(calculator.clear().value()).equal(0));

// prettier-ignore
it("can invert", () => expect(calculator.clear().add(2).inverse().value()).equal(1 / 2));
it('can invert', () => expect(calculator.clear().add(2).inverse().value()).equal(1 / 2));

// prettier-ignore
it("can sin", () => expect(calculator.clear().sin().value()).equal(0));
// prettier-ignore
it("can cos", () => expect(calculator.clear().cos().value()).equal(1));
// prettier-ignore
it("can tan", () => expect(calculator.clear().tan().value()).equal(0));
// prettier-ignore
it("can sinh", () => expect(calculator.clear().sinh().value()).equal(0));
// prettier-ignore
it("can cosh", () => expect(calculator.clear().cosh().value()).equal(1));
// prettier-ignore
it("can tanh", () => expect(calculator.clear().tanh().value()).equal(0));
// prettier-ignore
it("can asin", () => expect(calculator.clear().asin().value()).equal(0));
it('can sin', () => expect(calculator.clear().sin().value()).equal(0));
it('can cos', () => expect(calculator.clear().cos().value()).equal(1));
it('can tan', () => expect(calculator.clear().tan().value()).equal(0));
it('can sinh', () => expect(calculator.clear().sinh().value()).equal(0));
it('can cosh', () => expect(calculator.clear().cosh().value()).equal(1));
it('can tanh', () => expect(calculator.clear().tanh().value()).equal(0));
it('can asin', () => expect(calculator.clear().asin().value()).equal(0));
});
16 changes: 8 additions & 8 deletions src/Calculator.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import add from "./add";
import div from "./div";
import ln from "./ln";
import mod from "./mod";
import mul from "./mul";
import sub from "./sub";
import add from './add';
import div from './div';
import ln from './ln';
import mod from './mod';
import mul from './mul';
import sub from './sub';

/** A simple stateful calculator */
export default class Calculator {
protected current: number = 0;
protected current = 0;

constructor(initial: number = 0) {
constructor(initial = 0) {
this.current = initial;
}

Expand Down
12 changes: 6 additions & 6 deletions src/div.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { expect } from "chai";
import { describe, it } from "mocha";
import { describe, it } from 'mocha';
import { expect } from 'chai';

import div from "./div";
import div from './div';

describe("div", () => {
it("works for non-zero argments", () => expect(div(6, 2)).equal(3));
it("works for zero arguments", () => expect(div(3, 0)).equal(0));
describe('div', () => {
it('works for non-zero argments', () => expect(div(6, 2)).equal(3));
it('works for zero arguments', () => expect(div(3, 0)).equal(0));
});
14 changes: 7 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export { default as add } from "./add";
export { default as sub } from "./sub";
export { default as mul } from "./mul";
export { default as div } from "./div";
export { default as ln } from "./ln";
export { default as mod } from "./mod";
export { default as Calculator } from "./Calculator";
export { default as add } from './add';
export { default as sub } from './sub';
export { default as mul } from './mul';
export { default as div } from './div';
export { default as ln } from './ln';
export { default as mod } from './mod';
export { default as Calculator } from './Calculator';
18 changes: 9 additions & 9 deletions src/ln.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { expect } from "chai";
import { describe, it } from "mocha";
import { describe, it } from 'mocha';
import { expect } from 'chai';

import ln from "./ln";
import ln from './ln';

describe("ln", () => {
it("works for non-zero argments", () => expect(ln(1)).equal(0));
it("works for non-zero argments", () => expect(ln(Math.E)).equal(1));
it("works for zero arguments", () => expect(ln(0)).equal(0));
it("works for negative argments", () => expect(ln(-1)).equal(0));
it("works for negative argments", () => expect(ln(-Math.E)).equal(1));
describe('ln', () => {
it('works for non-zero argments ln(1)=0', () => expect(ln(1)).equal(0));
it('works for non-zero argments ln(e)=1', () => expect(ln(Math.E)).equal(1));
it('works for zero arguments ln(0)=0', () => expect(ln(0)).equal(0));
it('works for negative argments ln(-1)=0', () => expect(ln(-1)).equal(0));
it('works for negative argments ln(-e)=1', () => expect(ln(-Math.E)).equal(1));
});
8 changes: 7 additions & 1 deletion src/ln.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,11 @@
* Returns ln(-n), if `n` is negative and `0` if n is 0
*/
export default function ln(n: number): number {
return n === 0 ? 0 : n < 0 ? ln(-n) : Math.log(n);
if (n === 0) {
return 0;
}
if (n < 0) {
return ln(-n);
}
return Math.log(n);
}
12 changes: 6 additions & 6 deletions src/mod.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { expect } from "chai";
import { describe, it } from "mocha";
import { describe, it } from 'mocha';
import { expect } from 'chai';

import mod from "./mod";
import mod from './mod';

describe("mod", () => {
it("works for non-zero argments", () => expect(mod(6, 4)).equal(2));
it("works for zero arguments", () => expect(mod(3, 0)).equal(0));
describe('mod', () => {
it('works for non-zero argments', () => expect(mod(6, 4)).equal(2));
it('works for zero arguments', () => expect(mod(3, 0)).equal(0));
});
2 changes: 1 addition & 1 deletion src/mod.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* The modulus of two numbers
* Computes the modulus of two numbers
*
* Returns 0, if `b` is 0
*/
Expand Down
11 changes: 0 additions & 11 deletions tslint.json

This file was deleted.

Loading

0 comments on commit 19270d4

Please sign in to comment.