Skip to content
This repository was archived by the owner on Jun 11, 2022. It is now read-only.

Commit

Permalink
refactor: remove 'format' vs 'lint' differentiation
Browse files Browse the repository at this point in the history
unifies into one name, 'fix'. the differentiation was done in the first
place because formatters typically need less configuration and don't
output errors. but if that is so, we can include them with 'lint' since
they won't output errors. and since formatters aren't linters, we can
create a new 'fix' name
  • Loading branch information
hyperupcall committed Jun 5, 2020
1 parent abac4be commit 76be159
Show file tree
Hide file tree
Showing 28 changed files with 210 additions and 177 deletions.
4 changes: 2 additions & 2 deletions packages/fox-plugin-eslint/src/bin.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { bootstrapFunction, lintFunction } from "./";
import * as foxUtils from "fox-utils";
import { bootstrapFunction, fixFunction } from "./";
import { info } from './info'

export async function bin() {
await foxUtils.buildCli(process.argv, {
pluginName: info.name,
pluginDescription: info.description,
bootstrapFunction,
actionFunction: lintFunction
fixFunction
});
}
39 changes: 20 additions & 19 deletions packages/fox-plugin-eslint/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import path from 'path'
// @ts-ignore
import { ESLint } from "eslint";
import * as foxUtils from "fox-utils";
import eslintConfigFox from 'eslint-config-fox'
// @ts-ignore
import { ESLint } from "eslint";

export { info } from './info'

Expand All @@ -12,26 +12,27 @@ export async function bootstrapFunction() {
})
}

export async function lintFunction() {
export async function fixFunction() {
console.log('fix eslint')
// 1. Create an instance.
const eslint = new ESLint({
cwd: process.cwd(),
errorOnUnmatchedPattesrn: true,
globInputPaths: true,
// ignorePath: '',
overrideConfig: {
// const eslint = new ESLint({
// cwd: process.cwd(),
// errorOnUnmatchedPattesrn: true,
// globInputPaths: true,
// // ignorePath: '',
// overrideConfig: {

},
useEslintrc: false
});
// },
// useEslintrc: false
// });

// 2. Lint files.
const results = await eslint.lintFiles(["../**/*.js"]);
// // 2. Lint files.
// const results = await eslint.lintFiles(["../**/*.js"]);

// 3. Format the results.
const formatter = await eslint.loadFormatter("stylish");
const resultText = formatter.format(results);
// // 3. Format the results.
// const formatter = await eslint.loadFormatter("stylish");
// const resultText = formatter.format(results);

// 4. Output it.
console.log(resultText);
// // 4. Output it.
// console.log(resultText);
}
6 changes: 3 additions & 3 deletions packages/fox-plugin-htmlhint/src/bin.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { bootstrapFunction, lintFunction } from ".";
import { info } from './info'
import * as foxUtils from "fox-utils";
import { bootstrapFunction, fixFunction } from ".";
import { info } from './info'

export async function bin() {
await foxUtils.buildCli(process.argv, {
pluginName: info.name,
pluginDescription: info.description,
bootstrapFunction,
actionFunction: lintFunction
fixFunction
});
}
4 changes: 2 additions & 2 deletions packages/fox-plugin-htmlhint/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ export async function bootstrapFunction(): Promise<void> {
})
}

export async function lintFunction(fox: IFoxConfig): Promise<void> {

export async function fixFunction(fox: IFoxConfig): Promise<void> {
console.log('fix htmlhint')
}
5 changes: 3 additions & 2 deletions packages/fox-plugin-htmlhint/src/info.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import type { IPluginExportInfo } from 'fox-types'

export const info: IPluginExportInfo = {
name: '',
tool: 'Htmlhint',
name: 'fox-plugin-htmlhint',
tool: 'htmlhint',
toolName: 'Htmlhint',
toolConfigSchemaHelpUri: 'https://htmlhint.com/docs/user-guide/list-rules',
description: 'Lints the html files of current project',
descriptionLong: 'pending'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env node

const { bin } = require('../build/bin');
require = require('fox-esm')(module)

bin()
const { bin } = require("../build/bin");
bin();
1 change: 1 addition & 0 deletions packages/fox-plugin-markdown-lint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"license": "MIT",
"dependencies": {
"fox-test": "workspace:^1.0.0",
"fox-utils": "workspace:^0.1.1",
"markdown-extensions": "^1.1.1",
"remark": "^12.0.0",
"remark-cli": "^8.0.0",
Expand Down
16 changes: 9 additions & 7 deletions packages/fox-plugin-markdown-lint/src/bin.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { runMarkdownLint } from '.'
import * as foxUtils from "fox-utils";
import { bootstrapFunction, fixFunction } from "./";
import { info } from './info'

export async function bin() {
try {
await runMarkdownLint()
} catch (err) {
console.error(err)
process.exitCode = 1
}
await foxUtils.buildCli(process.argv, {
pluginName: info.name,
pluginDescription: info.description,
bootstrapFunction,
fixFunction
});
}
47 changes: 30 additions & 17 deletions packages/fox-plugin-markdown-lint/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,37 @@ import extensions from 'markdown-extensions'
import processor from 'remark'
// @ts-ignore
import proc from 'remark/package.json'
import type { IFoxConfig } from 'fox-types'
import * as foxUtils from 'fox-utils'

export { info } from './info'

export async function runMarkdownLint() {
// start({
// processor: processor,
// name: proc.name,
// description: cli.description,
// version: [
// proc.name + ': ' + proc.version,
// cli.name + ': ' + cli.version
// ].join(', '),
// pluginPrefix: proc.name,
// // @ts-ignore
// presetPrefix: proc.name + '-preset',
// packageField: proc.name + 'Config',
// rcName: '.' + proc.name + 'rc',
// ignoreName: '.' + proc.name + 'ignore',
// extensions: extensions
// })
export async function bootstrapFunction(): Promise<void> {
await foxUtils.buildBootstrap({
dirname: __dirname
})
}

export async function fixFunction(fox: IFoxConfig): Promise<void> {
console.log('fix markdownlint')
}


// export async function fixFunction() {
// // start({
// // processor: processor,
// // name: proc.name,
// // description: cli.description,
// // version: [
// // proc.name + ': ' + proc.version,
// // cli.name + ': ' + cli.version
// // ].join(', '),
// // pluginPrefix: proc.name,
// // // @ts-ignore
// // presetPrefix: proc.name + '-preset',
// // packageField: proc.name + 'Config',
// // rcName: '.' + proc.name + 'rc',
// // ignoreName: '.' + proc.name + 'ignore',
// // extensions: extensions
// // })
// }
3 changes: 2 additions & 1 deletion packages/fox-plugin-markdown-lint/src/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import type { IPluginExportInfo } from 'fox-types'

export const info: IPluginExportInfo = {
name: 'fox-plugin-markdown-lint',
tool: 'MarkdownLint',
tool: 'markdownlint',
toolName: 'MarkdownLint',
toolConfigSchemaHelpUri: '',
description: 'Lints markdown files',
descriptionLong: 'Lints markdown files. Has autofix capabilities?'
Expand Down
2 changes: 1 addition & 1 deletion packages/fox-plugin-package-json-lint/src/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ export async function bin() {
pluginName: info.name,
pluginDescription: info.description,
bootstrapFunction,
actionFunction: lintFunction
fixFunction: lintFunction
});
}
1 change: 1 addition & 0 deletions packages/fox-plugin-package-json-lint/src/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { IPluginExportInfo } from 'fox-types'
export const info: IPluginExportInfo = {
name: 'fox-plugin-package-json-lint',
tool: 'npm-package-json-lint',
toolName: 'npm-package-json-lint',
toolConfigSchemaHelpUri: 'https://npmpackagejsonlint.org/docs/en/rules',
description: 'Lints the pacakge.json file',
descriptionLong: 'Lints the package.json file. Has autofix?'
Expand Down
2 changes: 1 addition & 1 deletion packages/fox-plugin-package-json-sort/src/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ export async function bin() {
await foxUtils.buildCli(process.argv, {
pluginName: info.name,
pluginDescription: info.description,
actionFunction: formatFunction
fixFunction: formatFunction
});
}
1 change: 1 addition & 0 deletions packages/fox-plugin-package-json-sort/src/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { IPluginExportInfo } from 'fox-types'
export const info: IPluginExportInfo = {
name: 'fox-plugin-package-json-sort',
tool: 'packageJsonSort',
toolName: 'packageJsonSort',
toolConfigSchemaHelpUri: '',
description: 'Sorts the pacakge.json file',
descriptionLong: 'Lints the package.json file. Has autofix?'
Expand Down
2 changes: 1 addition & 1 deletion packages/fox-plugin-prettier/src/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ export async function bin() {
pluginName: info.name,
pluginDescription: info.description,
bootstrapFunction,
actionFunction: formatFunction
fixFunction: formatFunction
});
}
3 changes: 2 additions & 1 deletion packages/fox-plugin-prettier/src/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import type { IPluginExportInfo } from 'fox-types'

export const info: IPluginExportInfo = {
name: 'fox-plugin-prettier',
tool: 'Prettier',
tool: 'prettier',
toolName: 'Prettier',
toolConfigSchemaHelpUri: 'https://prettier.io/docs/en/options.html',
description: 'Formats common files',
descriptionLong: 'Formats common files?'
Expand Down
4 changes: 2 additions & 2 deletions packages/fox-plugin-stylelint/src/bin.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { bootstrapFunction, lintFunction } from "./";
import * as foxUtils from "fox-utils";
import { bootstrapFunction, fixFunction } from "./";
import { info } from './info'

export async function bin() {
await foxUtils.buildCli(process.argv, {
pluginName: info.name,
pluginDescription: info.description,
bootstrapFunction,
actionFunction: lintFunction
fixFunction
});
}
69 changes: 35 additions & 34 deletions packages/fox-plugin-stylelint/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,47 +13,48 @@ export async function bootstrapFunction(): Promise<void> {
})
}

export async function lintFunction(fox: IFoxConfig): Promise<void> {
export async function fixFunction(fox: IFoxConfig): Promise<void> {
await foxUtils.buildLint({
dirname: __dirname,
async fn() {
const { location } = await foxUtils.getProjectData();
foxUtils.setFoxOptionsToEnv(fox)
console.log('fix stylelint')
// const { location } = await foxUtils.getProjectData();
// foxUtils.setFoxOptionsToEnv(fox)

const config = (await import(path.join(location, '.config/stylelint.config.js'))).default(fox)
// const config = (await import(path.join(location, '.config/stylelint.config.js'))).default(fox)

const resolve = (module: string) =>
path.join(__dirname, `../node_modules/${module}`)
const stylelintConfigFoxPath =
path.join(__dirname, '../node_modules/stylelint-config-fox')
// const resolve = (module: string) =>
// path.join(__dirname, `../node_modules/${module}`)
// const stylelintConfigFoxPath =
// path.join(__dirname, '../node_modules/stylelint-config-fox')

config.extends = config.extends || [],
config.extends.unshift(stylelintConfigFoxPath)
// config.extends = config.extends || [],
// config.extends.unshift(stylelintConfigFoxPath)

const sharedOptions: Partial<stylelintType.i> | undefined = {
globbyOptions: {
cwd: location,
ignore: [],
caseSensitiveMatch: true, // default
dot: false, // default
gitignore: false // default
},
configBasedir: location,
fix: true,
formatter: "string",
cache: true,
cacheLocation: path.join(location, '.config/.stylelintcache'),
disableDefaultIgnores: true,
ignorePath: path.join(location, '.config/stylelintignore'),
reportNeedlessDisables: true,
reportInvalidScopeDisables: true
}
// const sharedOptions: Partial<stylelintType.i> | undefined = {
// globbyOptions: {
// cwd: location,
// ignore: [],
// caseSensitiveMatch: true, // default
// dot: false, // default
// gitignore: false // default
// },
// configBasedir: location,
// fix: true,
// formatter: "string",
// cache: true,
// cacheLocation: path.join(location, '.config/.stylelintcache'),
// disableDefaultIgnores: true,
// ignorePath: path.join(location, '.config/stylelintignore'),
// reportNeedlessDisables: true,
// reportInvalidScopeDisables: true
// }

const result = await stylelint.lint({
config,
files: '**/*.css',
...sharedOptions
})
// const result = await stylelint.lint({
// config,
// files: '**/*.css',
// ...sharedOptions
// })

// const config2: Partial<stylelint.Configuration> = config
// const i = resolve("postcss-scss/lib/scss-syntax.js");
Expand All @@ -70,7 +71,7 @@ export async function lintFunction(fox: IFoxConfig): Promise<void> {
// ...sharedOptions
// })

console.log('a', result.output)
// console.log('a', result.output)
}
})
}
2 changes: 0 additions & 2 deletions packages/fox-runner/src/entry.js

This file was deleted.

10 changes: 3 additions & 7 deletions packages/fox-suite/@types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@ interface IActionBootstrap extends IAction {
action: IPluginExportIndex["bootstrapFunction"] | IPluginExportIndex["bootstrapFunction"][]
}

interface IActionFormat extends IAction {
action: IPluginExportIndex["formatFunction"] | IPluginExportIndex["formatFunction"][],
interface IActionFix extends IAction {
action: IPluginExportIndex["fixFunction"] | IPluginExportIndex["fixFunction"][],
}

interface IActionLint extends IAction {
action: IPluginExportIndex["lintFunction"] | IPluginExportIndex["lintFunction"][]
}

export type IActionFunction = IActionBootstrap | IActionFormat | IActionLint
export type IActionFunction = IActionBootstrap | IActionFix
1 change: 1 addition & 0 deletions packages/fox-suite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"fox-plugin-package-json-sort": "workspace:^0.1.1",
"fox-plugin-prettier": "workspace:^0.1.0",
"fox-plugin-stylelint": "workspace:^0.1.0",
"fox-runner": "workspace:^0.1.1",
"fox-utils": "^0.1.1",
"lodash.uniq": "^4.5.0",
"minimist": "^1.2.5",
Expand Down
Loading

0 comments on commit 76be159

Please sign in to comment.