Skip to content

Commit

Permalink
Moving flat configuration format for eslint.
Browse files Browse the repository at this point in the history
  • Loading branch information
armfazh committed Jul 1, 2024
1 parent 749770b commit 4044ddf
Show file tree
Hide file tree
Showing 20 changed files with 5,568 additions and 5,261 deletions.
120 changes: 33 additions & 87 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,102 +1,48 @@
import globals from 'globals'
import tsParser from '@typescript-eslint/parser'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import js from '@eslint/js'
import { FlatCompat } from '@eslint/eslintrc'

const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all
})

export default [
import eslintJS from '@eslint/js'
import eslintTS from 'typescript-eslint'
import pluginPrettier from 'eslint-plugin-prettier/recommended'
import pluginSecurity from 'eslint-plugin-security'
import pluginJest from 'eslint-plugin-jest'

export default eslintTS.config(
eslintJS.configs.recommended,
...eslintTS.configs.strictTypeChecked,
pluginJest.configs['flat/recommended'],
pluginSecurity.configs.recommended,
{
ignores: ['coverage/*', 'src/sjcl/index.js', 'src/sjcl/index.d.ts', 'lib/*']
ignores: [
'jest.config.mjs',
'eslint.config.mjs',
'coverage/*',
'src/groupSjcl.ts',
'src/sjcl/index.js',
'src/sjcl/index.d.ts',
'lib/*'
]
},
...compat.extends(
'eslint:recommended',
'plugin:security/recommended-legacy',
'plugin:prettier/recommended'
),
{
languageOptions: {
globals: {
...globals.browser,
...globals.node
},

ecmaVersion: 2020,
sourceType: 'module',

parserOptions: {
project: true
project: true,
tsconfigRootDir: import.meta.dirname
}
}
},
...compat
.extends(
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'plugin:jest-formatting/recommended',
'plugin:jest/recommended',
'prettier'
)
.map((config) => ({
...config,
files: ['**/*.ts']
})),
{
files: ['**/*.ts'],

languageOptions: {
parser: tsParser,
ecmaVersion: 2020,
sourceType: 'module'
},

rules: {
'max-lines-per-function': [
'warn',
{
max: 100,
skipComments: true,
skipBlankLines: true
}
],

'max-statements': ['warn', 50],
'max-params': ['warn', 5],
'no-loop-func': 'warn',
'max-lines': 'off',
'no-ternary': 'off',
'no-inline-comments': 'off',
'line-comment-position': 'off',
'no-magic-numbers': 'off',
'id-length': 'off',
'max-classes-per-file': 'off',
'sort-keys': 'off',
'sort-vars': 'off',
'no-bitwise': 'off',
'no-plusplus': 'off',
'capitalized-comments': 'off',
'multiline-comment-style': 'off',
'func-style': ['error', 'declaration'],
'one-var': ['error', 'never'],
'@typescript-eslint/no-namespace': 'warn',

'@typescript-eslint/no-unused-vars': [
'error',
"@typescript-eslint/no-unused-vars": [
"error",
{
argsIgnorePattern: '^_'
"args": "all",
"argsIgnorePattern": "^_",
"caughtErrors": "all",
"varsIgnorePattern": "^_"
}
],

'@typescript-eslint/consistent-type-imports': 'error',
'@typescript-eslint/consistent-type-exports': 'error'
'@typescript-eslint/consistent-type-exports': 'error',
'@typescript-eslint/restrict-template-expressions': 'off'
}
}
]
},
pluginPrettier
)
27 changes: 17 additions & 10 deletions examples/facade/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,23 @@ export async function facadeVoprfExample(Oprf: OprfApi, suite: SuiteID = Oprf.Su
}

async function main() {
if (typeof crypto === 'undefined') {
Object.assign(global, { crypto: webcrypto })
try {
if (typeof crypto === 'undefined') {
Object.assign(global, { crypto: webcrypto })
}
await facadeOprfExample(Oprf)
await facadeVoprfExample(Oprf)

// This suite requires the noble crypto provider as sjcl doesn't support
// ristretto.
const OprfNoble = Oprf.withConfig({ crypto: CryptoNoble })
await facadePoprfExample(OprfNoble, Oprf.Suite.RISTRETTO255_SHA512)
} catch (_e: unknown) {
const e = _e as Error
console.log(`Error: ${e.message}`)
console.log(`Stack: ${e.stack}`)
process.exit(1)
}
await facadeOprfExample(Oprf)
await facadeVoprfExample(Oprf)

// This suite requires the noble crypto provider as sjcl doesn't support
// ristretto.
const OprfNoble = Oprf.withConfig({ crypto: CryptoNoble })
await facadePoprfExample(OprfNoble, Oprf.Suite.RISTRETTO255_SHA512)
}

main().catch(console.error)
void main()
3 changes: 2 additions & 1 deletion examples/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ async function examples() {
await poprfExample()
}

examples().catch((e: Error) => {
examples().catch((_e: unknown) => {
const e = _e as Error
console.log(`Error: ${e.message}`)
console.log(`Stack: ${e.stack}`)
process.exit(1)
Expand Down
Loading

0 comments on commit 4044ddf

Please sign in to comment.