Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable TypeScript Rules (without requiring type checking rules) #18

Merged
merged 10 commits into from
Mar 12, 2021
28 changes: 26 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,39 @@
on:
pull_request_target:
pull_request:
push:
branches:
- '*'
tags:
- 'v*'

jobs:
build:
runs-on: ubuntu-latest
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2

# Install dependencies
- uses: actions/setup-node@v1
with:
node-version: '12'
registry-url: 'https://registry.npmjs.org'
- run: npm ci

# Build
- run: npm pack
- uses: actions/upload-artifact@v2
with:
name: npm package
path: ./ni-eslint-config-*.tgz
if-no-files-found: error

# Test
- run: npm run test-typescript
- run: npm run test-typescript-typed
- run: npm run dev-print-typescript-props

# Publish
- if: startsWith(github.ref, 'refs/tags/v')
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
18 changes: 0 additions & 18 deletions .github/workflows/release.yml

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
.DS_Store
*.tgz
.vscode
8 changes: 7 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
module.exports = {
extends: 'airbnb-base',
extends: [
/*
airbnb-base source:
https://github.com/airbnb/javascript/blob/master/packages/eslint-config-airbnb-base/index.js
*/
'airbnb-base'
],
rules: {
/*
Omit arrow function parenthesis where they are not required to improve readability.
Expand Down
23 changes: 23 additions & 0 deletions lib/typescript-extensions-requiring-type-checking.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module.exports = {
rules: {
// Defined by Airbnb
// 'dot-notation': 'off',
// '@typescript-eslint/dot-notation': ['error', { allowKeywords: true }],

// Defined by Airbnb
// 'no-implied-eval': 'off',
// '@typescript-eslint/no-implied-eval': 'error',

// Defined by Airbnb
// 'no-throw-literal': 'off',
// '@typescript-eslint/no-throw-literal': 'error',

// Defined by Airbnb
// 'require-await': 'off',
// '@typescript-eslint/require-await': 'off',

// Defined by Airbnb
// 'no-return-await': 'off',
// '@typescript-eslint/return-await': 'error',
}
};
169 changes: 169 additions & 0 deletions lib/typescript-extensions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
module.exports = {
rules: {
/*
The following are extension rules that replace core JavaScript rules to support
TypeScript.
* When upgrading, changes to these rules can be identified in the typescript-eslint
changelog under features and breaking changes:
https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin#extension-rules
* In addition, the `npm run dev-print-typescript-props` command can be used to list
the expected extension properties.
* The value of the extension properties should match the value chosen by the
JavaScript / Airbnb configuration.
*/

// Defined by Airbnb
'brace-style': 'off',
'@typescript-eslint/brace-style': ['error', '1tbs', { allowSingleLine: true }],

// Defined by NI
'comma-dangle': 'off',
'@typescript-eslint/comma-dangle': ['error', 'only-multiline'],

// Defined by Airbnb
'comma-spacing': 'off',
'@typescript-eslint/comma-spacing': ['error', { before: false, after: true }],

// Defined by Airbnb
'default-param-last': 'off',
'@typescript-eslint/default-param-last': 'off',

// Defined by Airbnb
'func-call-spacing': 'off',
'@typescript-eslint/func-call-spacing': ['error', 'never'],

// Defined by NI
indent: 'off',
'@typescript-eslint/indent': ['error', 4],

// Defined by Airbnb
'init-declarations': 'off',
'@typescript-eslint/init-declarations': 'off',

// Defined by Airbnb
'keyword-spacing': 'off',
'@typescript-eslint/keyword-spacing': ['error', {
before: true,
after: true,
overrides: {
return: { after: true },
throw: { after: true },
case: { after: true }
}
}],

// Defined by Airbnb
'lines-between-class-members': 'off',
'@typescript-eslint/lines-between-class-members': ['error', 'always', { exceptAfterSingleLine: false }],
rajsite marked this conversation as resolved.
Show resolved Hide resolved

// Defined by Airbnb
'no-array-constructor': 'off',
'@typescript-eslint/no-array-constructor': 'error',

// Defined by Airbnb
'no-dupe-class-members': 'off',
'@typescript-eslint/no-dupe-class-members': 'error',

// Defined by Airbnb
'no-duplicate-imports': 'off',
'@typescript-eslint/no-duplicate-imports': 'off',

// Defined by Airbnb
'no-empty-function': 'off',
'@typescript-eslint/no-empty-function': ['error', {
allow: [
'arrowFunctions',
'functions',
'methods'
]
}],

// Defined by Airbnb
'no-extra-parens': 'off',
'@typescript-eslint/no-extra-parens': ['off', 'all', {
conditionalAssign: true,
nestedBinaryExpressions: false,
returnAssign: false,
ignoreJSX: 'all',
enforceForArrowConditionals: false,
}],

// Defined by Airbnb
'no-extra-semi': 'off',
'@typescript-eslint/no-extra-semi': 'error',

// Defined by Airbnb
'no-invalid-this': 'off',
'@typescript-eslint/no-invalid-this': 'off',

// Defined by NI
'no-loop-func': 'off',
'@typescript-eslint/no-loop-func': 'error',

// Defined by Airbnb
'no-loss-of-precision': 'off',
'@typescript-eslint/no-loss-of-precision': 'off',

// Defined by Airbnb
'no-magic-numbers': 'off',
'@typescript-eslint/no-magic-numbers': ['off', {
ignore: [],
ignoreArrayIndexes: true,
enforceConst: true,
detectObjects: false,
}],

// Defined by Airbnb
'no-redeclare': 'off',
'@typescript-eslint/no-redeclare': 'error',

// Defined by Airbnb
'no-shadow': 'off',
'@typescript-eslint/no-shadow': 'error',

// Defined by Airbnb
'no-unused-expressions': 'off',
'@typescript-eslint/no-unused-expressions': ['error', {
rajsite marked this conversation as resolved.
Show resolved Hide resolved
allowShortCircuit: false,
allowTernary: false,
allowTaggedTemplates: false,
}],

// Defined by Airbnb
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': ['error', { vars: 'all', args: 'after-used', ignoreRestSiblings: true }],

// Defined by NI
'no-use-before-define': 'off',
'@typescript-eslint/no-use-before-define': ['error', { functions: false, classes: true, variables: true }],

// Defined by Airbnb
'no-useless-constructor': 'off',
'@typescript-eslint/no-useless-constructor': 'error',

// Available in newer typescript-eslint version
rajsite marked this conversation as resolved.
Show resolved Hide resolved
// Defined by Airbnb
// 'object-curly-spacing': 'off',
// '@typescript-eslint/object-curly-spacing': ['error', 'always'],

// Defined by Airbnb
quotes: 'off',
'@typescript-eslint/quotes': ['error', 'single', { avoidEscape: true }],

// Defined by Airbnb
semi: 'off',
'@typescript-eslint/semi': ['error', 'always'],

// Defined by NI
'space-before-function-paren': 'off',
'@typescript-eslint/space-before-function-paren': ['error', {
anonymous: 'always',
named: 'never',
asyncArrow: 'always'
}],

// Defined by Airbnb
'space-infix-ops': 'off',
'@typescript-eslint/space-infix-ops': 'error',
}
};
41 changes: 41 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
"main": "index.js",
"scripts": {
"prepare": "npm test",
"test": "eslint ."
"test": "eslint .",
"test-typescript": "eslint ./test/typescript/",
"test-typescript-typed": "eslint ./test/typescript-type-checking/",
"dev-print-typescript-props": "node ./tools/print-typescript-properties"
},
"repository": {
"type": "git",
Expand All @@ -26,16 +29,18 @@
"access": "public"
},
"files": [
".eslintrc.js",
"typescript.js"
"/*.js",
"/lib/*"
],
"dependencies": {
"@typescript-eslint/parser": "^4.9.1",
"eslint-config-airbnb-base": "~14.2.0"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^4.9.1",
"eslint": "^7.6.0",
"eslint-plugin-import": "^2.22.0"
"eslint-plugin-import": "^2.22.0",
"typescript": "^4.1.3"
},
"peerDependencies": {
"@typescript-eslint/eslint-plugin": "^4.9.1",
Expand Down
9 changes: 9 additions & 0 deletions test/typescript-type-checking/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
extends: '../../typescript-requiring-type-checking',
root: true,
ignorePatterns: ['*.js'],
parserOptions: {
project: ['./tsconfig.json'],
tsconfigRootDir: __dirname,
},
};
13 changes: 13 additions & 0 deletions test/typescript-type-checking/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// TypeScript Smoke Test

export default class NI {
private _awesomeLevel = 1;

public get awesome(): boolean {
return this._awesomeLevel > 0;
}

public makeAwesomer(): void {
this._awesomeLevel += 1;
}
}