-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests, fixed naming-convention config
- Loading branch information
Showing
8 changed files
with
138 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,4 @@ | |
/.gitignore | ||
/.markdownlint.json | ||
/.eslintrc | ||
/eslint.test.js | ||
/tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
const configs = [ | ||
{ | ||
// default | ||
'selector': 'default', | ||
'format': ['camelCase'], | ||
'leadingUnderscore': 'forbid', | ||
'trailingUnderscore': 'forbid' | ||
}, | ||
{ | ||
// const global variables can be UPPER_CASE | ||
'selector': 'variable', | ||
'modifiers': ['const', 'global'], | ||
'format': ['camelCase', 'UPPER_CASE'] | ||
}, | ||
{ | ||
// unused parameters start with _ | ||
'selector': 'parameter', | ||
'modifiers': ['unused'], | ||
'leadingUnderscore': 'allow', | ||
'format': null | ||
}, | ||
{ | ||
// enums | ||
'selector': 'enumMember', | ||
'format': ['UPPER_CASE'] | ||
}, | ||
{ | ||
// types | ||
'selector': 'typeLike', | ||
'format': ['PascalCase'] | ||
} | ||
]; | ||
const reactConfigs = [ | ||
{ | ||
// const global variables of function type can be PascalCase for React Components | ||
'selector': 'variable', | ||
'modifiers': ['const', 'global'], | ||
'types': ['function'], | ||
'format': ['camelCase', 'UPPER_CASE', 'PascalCase'] | ||
}, | ||
{ | ||
// Components passed as props | ||
'selector': 'property', | ||
'filter': 'Comp(onent)?$', | ||
'format': ['camelCase', 'PascalCase'] | ||
}, | ||
{ | ||
// react hooks defined as const variables | ||
'selector': 'variable', | ||
'types': ['function'], | ||
'filter': '^use', | ||
'format': ['camelCase'] | ||
}, | ||
{ | ||
// react hooks defined as function | ||
'selector': 'function', | ||
'filter': '^use', | ||
'format': ['camelCase'] | ||
} | ||
]; | ||
|
||
module.exports = ({ isReact = false } = {}, level = 'error') => [level].concat( | ||
configs, | ||
isReact ? reactConfigs : [] | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* eslint-env node */ | ||
/* eslint-disable no-console */ | ||
|
||
const { ESLint } = require('eslint'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
/** | ||
* @returns {promise is PromiseRejectedResult} | ||
*/ | ||
function filterRejected(promise) { | ||
return promise.status === 'rejected' | ||
} | ||
|
||
async function getErrors(configFile) { | ||
const cli = new ESLint({ | ||
overrideConfig: { | ||
extends: [path.resolve(configFile)], | ||
parserOptions: { | ||
project: './tests/tsconfig.json' | ||
} | ||
} | ||
}); | ||
|
||
const results = await Promise.allSettled([ | ||
cli.lintText('', { filePath: 'file.js' }), | ||
cli.lintText('', { filePath: 'file.jsx' }), | ||
cli.lintText('', { filePath: 'file.ts' }), | ||
cli.lintText('', { filePath: 'file.tsx' }) | ||
]); | ||
const rejectReasons = results.filter(filterRejected).map(promise => promise.reason) | ||
|
||
if (rejectReasons.length > 0) { | ||
throw rejectReasons | ||
} | ||
} | ||
|
||
async function run() { | ||
const files = await fs.promises.readdir('.', { withFileTypes: true }); | ||
const configs = files.filter(file => file.isFile() && file.name.startsWith('eslint-config') && file.name.endsWith('.js')); | ||
|
||
let errored = false; | ||
|
||
configs.forEach(async f => { | ||
try { | ||
await getErrors(f.name); | ||
} catch (errors) { | ||
console.error('Error in config file', f.name); | ||
console.error(errors); | ||
|
||
errored = true; | ||
} | ||
}); | ||
|
||
if (errored) { | ||
process.exit(1); | ||
} | ||
} | ||
run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"compilerOptions": {} | ||
} |