Skip to content

Commit

Permalink
Add Typescript support (#588)
Browse files Browse the repository at this point in the history
* Add Typescript support

* Apply CR suggestions

Co-authored-by: Matthew Peveler <matt.peveler@gmail.com>

* Use default tsconfig for dev and tsconfig.build for the build

It makes the text editor properly parse and lint any code during development.
Without this change the test files were not being transpiled properly by my text editor.

* Drop Babel from src/browser code

We don't need it anymore because of Typescript

Co-authored-by: Matthew Peveler <matt.peveler@gmail.com>
  • Loading branch information
maxcnunes and MasterOdin committed Mar 3, 2021
1 parent 7cb9e5f commit 9a63a8f
Show file tree
Hide file tree
Showing 56 changed files with 1,808 additions and 2,275 deletions.
37 changes: 0 additions & 37 deletions .babelrc.json

This file was deleted.

148 changes: 148 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
module.exports = {
parserOptions: {
sourceType: 'module',
ecmaVersion: 2020,
},
extends: ['eslint:recommended', 'prettier'],
plugins: ['prettier'],
rules: {
'prettier/prettier': ['error'],
},
env: {
es2017: true,
node: true,
mocha: true,
},
overrides: [
{
files: ['src/renderer/**/*.js', 'src/renderer/**/*.jsx'],
plugins: ['import', 'react', 'prettier'],
extends: [
'eslint:recommended',
'plugin:react/recommended',
'plugin:jsx-a11y/recommended',
'plugin:prettier/recommended',
],
env: {
node: true,
browser: true,
es6: true,
},
parser: '@babel/eslint-parser',
parserOptions: {
sourceType: 'module',
ecmaVersion: 2020,
ecmaFeatures: {
jsx: true,
},
},
settings: {
react: { version: 'detect' },
},
globals: {
$: true,
},
rules: {
'no-unused-vars': 'off',
camelcase: [
'error',
{
properties: 'never',
ignoreDestructuring: false,
allow: ['^UNSAFE_'],
},
],
'no-use-before-define': 0,
'react/jsx-closing-bracket-location': 0,
'react/jsx-first-prop-new-line': 0,
'react/jsx-uses-react': 2,
'react/jsx-uses-vars': 2,
'react/react-in-jsx-scope': 2,
'react/forbid-prop-types': 0,
'space-before-function-paren': 0,
'func-names': 0,
'class-methods-use-this': 0,
'no-restricted-syntax': 0,
'no-bitwise': 0,
'prefer-destructuring': 0,
'react/button-has-type': 0,
'react/jsx-no-bind': 0,
'react/destructuring-assignment': 0,
'react/no-access-state-in-setstate': 0,
'react/no-array-index-key': 0,
'react/no-find-dom-node': 0,
'react/no-string-refs': 0,
'react/no-unused-prop-types': 0,
'react/no-unused-state': 0,
'react/prefer-stateless-function': 0,
'react/prop-types': 0,
'react/require-default-props': 0,
'react/static-property-placement': ['error', 'static public field'],
'jsx-a11y/anchor-is-valid': 0,
'jsx-a11y/no-autofocus': 0,
'jsx-a11y/click-events-have-key-events': 0,
'jsx-a11y/label-has-associated-control': 0,
'jsx-a11y/label-has-for': 0,
'jsx-a11y/no-noninteractive-tabindex': 0,
'jsx-a11y/no-static-element-interactions': 0,
},
},
{
files: ['src/**/*.ts', 'src/**/*.tsx'],
env: { browser: true, es6: true, node: true },
extends: [
'eslint:recommended',
'plugin:react/recommended',
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
globals: { NodeJS: true, Atomics: 'readonly', SharedArrayBuffer: 'readonly' },
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaFeatures: { jsx: true },
ecmaVersion: 2020,
sourceType: 'module',
project: './tsconfig.json',
},
plugins: ['prettier', '@typescript-eslint'],
rules: {
'no-unused-vars': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off', // temporary disable for tests
},
settings: {
react: { version: 'detect' },
},
},
{
files: ['test/**/*.ts', 'test/**/*.tsx'],
env: { browser: true, es6: true, node: true },
extends: [
'eslint:recommended',
'plugin:react/recommended',
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
globals: { NodeJS: true, Atomics: 'readonly', SharedArrayBuffer: 'readonly' },
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaFeatures: { jsx: true },
ecmaVersion: 2020,
sourceType: 'module',
project: './tsconfig.json',
},
plugins: ['prettier', '@typescript-eslint'],
rules: {
'no-unused-vars': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off', // temporary disable for tests
'@typescript-eslint/no-non-null-assertion': 'off',
},
settings: {
react: { version: 'detect' },
},
},
],
};
15 changes: 0 additions & 15 deletions .eslintrc.json

This file was deleted.

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ installers
npm-debug.log
.DS_Store
.tmp
*.tsbuildinfo

# test files
*.sqlite3
*.db
test/fixtures/sqlite/sqlectron.json

4 changes: 2 additions & 2 deletions .lintstagedrc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"*.{js,jsx}": ["eslint --fix"],
"*.{js,jsx,json,css,md}": ["prettier --write"]
"*.{js,jsx,ts,tsx}": ["eslint --fix"],
"*.{js,jsx,ts,tsx,json,css,md}": ["prettier --write"]
}
2 changes: 1 addition & 1 deletion .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"printWidth": 100,
"trailingComma": "es5",
"trailingComma": "all",
"semi": true,
"singleQuote": true,
"arrowParens": "always",
Expand Down
24 changes: 24 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module.exports = {
presets: [
[
'@babel/preset-env',
{
targets: {
chrome: 53,
},
useBuiltIns: 'usage',
corejs: { version: 3, proposals: true },
},
],
'@babel/preset-react',
'@babel/preset-typescript',
],
plugins: [
[
'@babel/plugin-proposal-class-properties',
{
loose: true,
},
],
],
};
Loading

0 comments on commit 9a63a8f

Please sign in to comment.