Skip to content

Commit

Permalink
feat: update ts config and new linter (#697)
Browse files Browse the repository at this point in the history
- add "isolatedModules": true,
- "importsNotUsedAsValues": "error",
- "noImplicitAny": true,
- add a must read section to the ts docs
- self lint

BREAKING CHANGE: tsconfig changed and linter has new rules for ts files.
  • Loading branch information
hugomrdias authored Dec 17, 2020
1 parent 605cd2a commit e11b8fe
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 76 deletions.
9 changes: 2 additions & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: yarn
- name: lint
run: yarn lint
- run: npm install
- run: npm run lint
- name: dependencies
run: ./cli.js dep-check -- -i aegir
- uses: ./actions/bundle-size
name: size
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
test-node:
needs: check
runs-on: ${{ matrix.os }}
Expand Down
8 changes: 8 additions & 0 deletions md/ts-jsdoc.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ When installing a dependency from a git url (ie. PRs depending on other PRs) the

Typescript can infere lots of the types without any help, but you can improve your code types by using just JSDoc for that follow the official TS documentation https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html.

## Must read references
[10 Insights from Adopting TypeScript at Scale](https://www.techatbloomberg.com/blog/10-insights-adopting-typescript-at-scale/)
[Typescript official performance notes](https://github.com/microsoft/TypeScript/wiki/Performance)
[TypeScript: Don’t Export const enums](https://ncjamieson.com/dont-export-const-enums/)
[TypeScript: Prefer Interfaces](https://ncjamieson.com/prefer-interfaces/)



### Rules for optimal type declarations and documentation

This list is a WIP, more rules will be added as we identify them.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"dirty-chai": "^2.0.1",
"electron-mocha": "^10.0.0",
"eslint": "^7.15.0",
"eslint-config-ipfs": "^0.1.0",
"eslint-config-ipfs": "^1.0.0",
"execa": "^5.0.0",
"extract-zip": "^2.0.1",
"findup-sync": "^4.0.0",
Expand Down
5 changes: 3 additions & 2 deletions src/config/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const merge = require('webpack-merge')
const webpack = require('webpack')
const path = require('path')
const webpackConfig = require('./webpack.config')
const { fromRoot, hasFile } = require('../utils')
const userConfig = require('./user')()
Expand Down Expand Up @@ -56,7 +57,7 @@ const karmaConfig = (config, argv) => {
invert: argv.invert
}

const karmaEntry = `${__dirname}/karma-entry.js`
const karmaEntry = path.join(__dirname, 'karma-entry.js')

if (!files.length) {
// only try to load *.spec.js if we aren't specifying custom files
Expand Down Expand Up @@ -139,7 +140,7 @@ const karmaConfig = (config, argv) => {
}

module.exports = (config) => {
var argv = require('yargs-parser')(process.argv.slice(2), {
const argv = require('yargs-parser')(process.argv.slice(2), {
array: ['files-custom'],
boolean: ['progress', 'bail'],
string: ['timeout']
Expand Down
42 changes: 20 additions & 22 deletions src/config/tsconfig.aegir.json
Original file line number Diff line number Diff line change
@@ -1,37 +1,35 @@
{
"compilerOptions": {
"strict": true,
// project options
"outDir": "dist",
"allowJs": true,
"checkJs": true,
"forceConsistentCasingInFileNames": true,
"noImplicitReturns": false,
"noImplicitAny": false,
"noImplicitThis": true,
"noFallthroughCasesInSwitch": true,
"noUnusedLocals": true,
"noUnusedParameters": false,
"strictFunctionTypes": true,
"strictNullChecks": true,
"strictPropertyInitialization": true,
"strictBindCallApply": true,
"strict": true,
"skipLibCheck": true,
"alwaysStrict": true,
"esModuleInterop": true,
"stripInternal": true,
"resolveJsonModule": true,
"preserveConstEnums": true,
"removeComments": false,
"target": "ES2019",
"moduleResolution": "node",
"lib": ["ES2019", "ES2020.Promise", "ES2020.String", "ES2020.BigInt", "DOM", "DOM.Iterable"],
"noEmitOnError": true,
"noEmit": false,
"noEmitOnError": true,
"emitDeclarationOnly": true,
"declaration": true,
"declarationMap": true,
"incremental": true,
"composite": true,
"outDir": "dist"
"isolatedModules": true,
"removeComments": false,
// module resolution
"esModuleInterop": true,
"moduleResolution": "node",
// linter checks
"noImplicitReturns": false,
"noFallthroughCasesInSwitch": true,
"noUnusedLocals": true,
"noUnusedParameters": false,
// advanced
"importsNotUsedAsValues": "error",
"forceConsistentCasingInFileNames": true,
"skipLibCheck": true,
"stripInternal": true,
"resolveJsonModule": true
},
"include": ["src"]
}
86 changes: 44 additions & 42 deletions src/config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,48 +117,50 @@ const base = (env, argv) => {
})
],
target: 'web',
node: process.env.AEGIR_NODE === 'false' ? {
global: true,
__filename: 'mock',
__dirname: 'mock',
dgram: false,
fs: false,
net: false,
tls: false,
child_process: false,
console: false,
// TODO remove this once readable-stream is fixed probably on in v4
// https://github.com/nodejs/readable-stream/pull/435
process: true,
Buffer: false,
setImmediate: false,
os: false,
assert: false,
constants: false,
events: false,
http: false,
path: false,
querystring: false,
stream: false,
string_decoder: false,
timers: false,
url: false,
util: false,
crypto: false
} : {
dgram: 'empty',
fs: 'empty',
net: 'empty',
tls: 'empty',
child_process: 'empty',
console: false,
global: true,
process: true,
__filename: 'mock',
__dirname: 'mock',
Buffer: true,
setImmediate: true
},
node: process.env.AEGIR_NODE === 'false'
? {
global: true,
__filename: 'mock',
__dirname: 'mock',
dgram: false,
fs: false,
net: false,
tls: false,
child_process: false,
console: false,
// TODO remove this once readable-stream is fixed probably on in v4
// https://github.com/nodejs/readable-stream/pull/435
process: true,
Buffer: false,
setImmediate: false,
os: false,
assert: false,
constants: false,
events: false,
http: false,
path: false,
querystring: false,
stream: false,
string_decoder: false,
timers: false,
url: false,
util: false,
crypto: false
}
: {
dgram: 'empty',
fs: 'empty',
net: 'empty',
tls: 'empty',
child_process: 'empty',
console: false,
global: true,
process: true,
__filename: 'mock',
__dirname: 'mock',
Buffer: true,
setImmediate: true
},
performance: {
hints: false
},
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/js+ts/src/another.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { hello } from './typed'

export const main = ():void => {
export const main = (): void => {
hello('world')
}
2 changes: 1 addition & 1 deletion test/fixtures/js+ts/src/typed.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const hello = (name:string):string => {
export const hello = (name: string): string => {
return `Hello ${name}`
}
9 changes: 9 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./src/config/tsconfig.aegir.json",
"compilerOptions": {
"outDir": "dist"
},
"include": [
"src", "test"
]
}

0 comments on commit e11b8fe

Please sign in to comment.