Skip to content

Commit

Permalink
ci: add website lint rules and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wellwelwel committed Nov 21, 2023
1 parent ce01c6f commit f5ce8cc
Show file tree
Hide file tree
Showing 31 changed files with 3,366 additions and 875 deletions.
5 changes: 4 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
website/
website/build
website/.docusaurus
website/.cache-loader
website/**/*.mdx
2 changes: 1 addition & 1 deletion .github/workflows/gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
with:
node-version: '18.x'

- name: Cache dependencies
- name: Cache Dependencies
uses: actions/cache@v3
with:
path: ~/.npm
Expand Down
37 changes: 37 additions & 0 deletions .github/workflows/website.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: 'GitHub Pages'
on:
pull_request:
paths:
- 'website/**'
workflow_dispatch:

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Actions - Checkout
uses: actions/checkout@v3

- name: Actions - Setup NodeJS
uses: actions/setup-node@v3
with:
node-version: '18.x'

- name: Cache Dependencies
uses: actions/cache@v3
with:
path: ~/.npm
key: npm-${{ hashFiles('package-lock.json') }}
restore-keys: npm-

- name: Installing Dependencies
run: cd website && npm ci

- name: Lint Checking
run: cd website && npm run lintcheck

- name: Checking Types
run: cd website && npm run typecheck

- name: Checking Build
run: cd website && npm run build
4 changes: 4 additions & 0 deletions website/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/build
/.docusaurus
/.cache-loader
/**/*.mdx
119 changes: 119 additions & 0 deletions website/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint", "import", "react", "react-hooks"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:import/errors",
"plugin:import/warnings",
"plugin:react-hooks/recommended",
"plugin:react/jsx-runtime"
],
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"rules": {
"import/no-cycle": ["error", { "maxDepth": "∞" }],
"import/no-unresolved": ["error", { "ignore": ["^@docusaurus/"] }],
"no-restricted-syntax": [
"error",
{
"selector": "ImportDeclaration[source.value=/^\\./][source.value!=/\\.(js(on(c)?)?|(s)?css|svg|ico)$/]",
"message": "Local imports must have the explicit extension"
}
],
"max-len": [
"error",
{
"code": 120,
"ignoreComments": true,
"ignoreTrailingComments": true,
"ignoreUrls": true,
"ignoreStrings": true,
"ignoreTemplateLiterals": true,
"ignoreRegExpLiterals": true
}
],
"eol-last": ["error", "always"],
"eqeqeq": [2, "always"],
"no-var": 2,
"block-scoped-var": 2,
"no-async-promise-executor": 2,
"no-bitwise": [2, { "allow": ["~"] }],
"no-duplicate-imports": [2, { "includeExports": true }],
"no-eq-null": 2,
"no-multiple-empty-lines": [2, { "max": 1, "maxEOF": 0 }],
"no-template-curly-in-string": 2,
"no-unneeded-ternary": 2,
"quote-props": [2, "as-needed"],
"require-await": 2,
"rest-spread-spacing": [2, "never"],
"semi-spacing": 2,
"space-before-function-paren": [
2,
{ "anonymous": "always", "named": "never", "asyncArrow": "always" }
],
"space-unary-ops": 2,
"yoda": 2,
"no-const-assign": 2,
"no-extra-semi": 2,
"for-direction": 2,
"no-eval": 2,
"indent": ["error", 2, { "offsetTernaryExpressions": true }],
"no-empty": ["error", { "allowEmptyCatch": true }]
},
"env": {
"browser": true,
"node": true
},
"overrides": [
{
"files": ["*.ts", "*.tsx"],
"rules": {
"@typescript-eslint/semi": ["error", "always"],
"@typescript-eslint/quotes": [
"error",
"single",
{ "avoidEscape": true, "allowTemplateLiterals": true }
],
"@typescript-eslint/no-empty-function": [
"error",
{ "allow": ["arrowFunctions"] }
],
"@typescript-eslint/indent": [
"error",
2,
{ "offsetTernaryExpressions": true }
]
}
},
{
"files": ["*.js"],
"parserOptions": {
"project": null
},
"rules": {
"semi": ["error", "always"],
"quotes": [
"error",
"single",
{ "avoidEscape": true, "allowTemplateLiterals": true }
],
"no-unused-vars": 2
}
}
],
"settings": {
"import/resolver": {
"typescript": {
"alwaysTryTypes": true,
"extensions": [".js", ".ts", "*.jsx", ".tsx"]
}
}
}
}
5 changes: 5 additions & 0 deletions website/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/build
/.docusaurus
/.cache-loader
# /**/*.mdx
package-lock.json
17 changes: 17 additions & 0 deletions website/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"printWidth": 80,
"tabWidth": 2,
"semi": true,
"singleQuote": true,
"quoteProps": "as-needed",
"jsxSingleQuote": true,
"trailingComma": "es5",
"bracketSpacing": true,
"bracketSameLine": false,
"arrowParens": "always",
"proseWrap": "preserve",
"htmlWhitespaceSensitivity": "css",
"endOfLine": "auto",
"embeddedLanguageFormatting": "auto",
"singleAttributePerLine": false
}
2 changes: 1 addition & 1 deletion website/docs/api-and-configurations.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ MySQL2 is mostly API compatible with [Node MySQL][node-mysql].
One known incompatibility is that `DECIMAL` values are returned as strings whereas in [Node MySQL][node-mysql] they are returned as numbers. This includes the result of `SUM()` and `AVG()` functions when applied to `INTEGER` arguments. This is done deliberately to avoid loss of precision - see https://github.com/sidorares/node-mysql2/issues/935.

:::info
If you find any other incompatibility with [Node MySQL][node-mysql], Please report via Issue tracker. We will fix reported incompatibility on priority basis.
If you find any other incompatibility with [Node MySQL][node-mysql], Please report via Issue tracker. We will fix reported incompatibility on priority basis.
:::

[node-mysql]: https://github.com/mysqljs/mysql
6 changes: 4 additions & 2 deletions website/docs/documentation/00-introduction.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

MySQL2 aims to be a drop in replacement for [node-mysql](https://github.com/mysqljs/mysql). Please check `node-mysql` for full documentation.

**Note :** *If you see any API incompatibilities with `node-mysql`, please report via github issue.*
**Note :** _If you see any API incompatibilities with `node-mysql`, please report via github issue._

Not only `Node-MySQL2` offers better performance over `node-mysql`, we also support these additional features.

Expand All @@ -27,9 +27,10 @@ Please check these [examples](/docs/examples) for `node-mysql2`.
## Known incompatibilities with `node-mysql`

- `zeroFill` flag is ignored in type conversion.
You need to check corresponding field's zeroFill flag and convert to string manually if this is of importance to you.
You need to check corresponding field's zeroFill flag and convert to string manually if this is of importance to you.

- `DECIMAL` and `NEWDECIMAL` types always returned as `string` unless you pass this config option:

```js
{
decimalNumbers: true,
Expand All @@ -53,6 +54,7 @@ This option could lose precision on the number as Javascript Number is a Float!
---

## Benchmarks

- https://gist.github.com/sidorares/ffe9ee9c423f763e3b6b
- `npm run benchmarks`
- [node-mysql-benchmarks](https://github.com/mscdex/node-mysql-benchmarks)
Expand Down
32 changes: 17 additions & 15 deletions website/docs/documentation/authentication-switch.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ const conn = mysql.createConnection({
password: 'test',
database: 'test_database',
authPlugins: {
'ssh-key-auth': function ({password}) {
'ssh-key-auth': function ({ password }) {
return function (pluginData) {
return getPrivate(key)
.then(key => {
.then((key) => {
const response = encrypt(key, password, pluginData);
// continue handshake by sending response data
return response;
})
.catch(err => {
.catch((err) => {
// throw error to propagate error to connect/changeUser handlers
});
};
}
}
},
},
});
```

Expand All @@ -46,27 +46,29 @@ const conn = mysql.createConnection({
user: 'test_user',
password: 'test',
database: 'test_database',
authSwitchHandler: function ({pluginName, pluginData}, cb) {
authSwitchHandler: function ({ pluginName, pluginData }, cb) {
if (pluginName === 'ssh-key-auth') {
getPrivateKey(key => {
getPrivateKey((key) => {
const response = encrypt(key, pluginData);
// continue handshake by sending response data
// respond with error to propagate error to connect/changeUser handlers
cb(null, response);
});
} else {
const err = new Error(`Unknown AuthSwitchRequest plugin name ${pluginName}`);
const err = new Error(
`Unknown AuthSwitchRequest plugin name ${pluginName}`
);
err.fatal = true;
cb(err);
}
}
},
});
```

The initial handshake is always performed using `mysql_native_password` plugin. This will be possible to override in future versions.

Note that if the `mysql_native_password` method is requested it will be handled internally according
to [Authentication::Native41]( https://dev.mysql.com/doc/internals/en/secure-password-authentication.html#packet-Authentication::Native41)
to [Authentication::Native41](https://dev.mysql.com/doc/internals/en/secure-password-authentication.html#packet-Authentication::Native41)
and no `authPlugins` function or the `authSwitchHandler` will be invoked.

These MAY be called multiple times if the plugin algorithm requires multiple roundtrips of data
Expand All @@ -89,21 +91,21 @@ const conn = mysql.createConnection({
database: 'test_database',
authPlugins: {
// password1 === password
'auth-plugin1': function ({password1}) {
'auth-plugin1': function ({ password1 }) {
return function (serverPluginData) {
return clientPluginData(password1, serverPluginData);
};
},
'auth-plugin2': function ({password2}) {
'auth-plugin2': function ({ password2 }) {
return function (serverPluginData) {
return clientPluginData(password2, serverPluginData);
};
},
'auth-plugin3': function ({password3}) {
'auth-plugin3': function ({ password3 }) {
return function (serverPluginData) {
return clientPluginData(password3, serverPluginData);
};
}
}
},
},
});
```
Loading

0 comments on commit f5ce8cc

Please sign in to comment.