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

Switch on the eslint formatting config within ofmt #60

Merged
merged 1 commit into from
Nov 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions ofmt/bin/ofmt.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ import {install} from '../lib/install.js'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const packageRoot = path.resolve(__dirname, '..')

const prettierConfigPath = [
const relativePrettierConfigPath = [
'../prettier-config-ofmt/index.json', // Path within another package, where 'ofmt' is installed as a dependency.
'node_modules/@ottofeller/prettier-config-ofmt/index.json', // Path within this package.
].find((filePath) => {
const fullPath = path.resolve(packageRoot, filePath)

try {
return statSync(fullPath)
} catch {
Expand All @@ -23,7 +24,7 @@ const prettierConfigPath = [
}
})

if (!prettierConfigPath) {
if (!relativePrettierConfigPath) {
console.error('Prettier config file is not found. Please install "@ottofeller/prettier-config-ofmt".')
process.exit(1)
}
Expand All @@ -40,12 +41,16 @@ if (args.input[0] === 'install') {
install(args.input[1] || './', args.flags.srcPath)
} else {
const checkOrWrite = args.flags.lint ? 'check' : 'write --list-different'
const configPath = path.resolve(packageRoot, prettierConfigPath)
const prettierConfigPath = path.resolve(packageRoot, relativePrettierConfigPath)

const eslintConfigPath = path.resolve(
packageRoot,
'node_modules/@ottofeller/eslint-config-ofmt/eslint.formatting.cjs',
)

;[
`npx prettier --${checkOrWrite} --config ${configPath} ${args.input}`,
// TODO Uncomment when the config is published.
// `npx eslint --config @ottofeller/eslint-config-ofmt/eslint.layout.cjs ${args.flags.lint ? '' : '--fix'} ${args.input}`,
`npx prettier --${checkOrWrite} --config ${prettierConfigPath} ${args.input}`,
`npx eslint --config ${eslintConfigPath} ${args.flags.lint ? '' : '--fix'} ${args.input}`,
].forEach((command) => {
exec(command, (error, stdout, stderr) => {
console.log(stdout)
Expand Down
2 changes: 0 additions & 2 deletions ofmt/lib/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,12 @@ export const install = (refDirRaw, srcPath) => {
const existingConfig = packageJson.eslintConfig.extends

// TODO: This disable directive remains for compatibility with the previous config. Delete when settled.
// eslint-disable-next-line max-depth -- allow depth 2 for cleaner conditions
if (Array.isArray(existingConfig) && !existingConfig.includes(eslintConfigPath)) {
packageJson.eslintConfig.extends.push(eslintConfigPath)
reportExtension()
}

// TODO: This disable directive remains for compatibility with the previous config. Delete when settled.
// eslint-disable-next-line max-depth -- allow depth 2 for cleaner conditions
if (!Array.isArray(existingConfig) && existingConfig !== eslintConfigPath) {
packageJson.eslintConfig.extends = [existingConfig, eslintConfigPath]
reportExtension()
Expand Down
Loading