-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: @putout/plugin-eslint: apply-dir-to-flat
- Loading branch information
1 parent
b0c8fac
commit d1deb4b
Showing
11 changed files
with
124 additions
and
15 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
3 changes: 3 additions & 0 deletions
3
packages/plugin-eslint/lib/apply-dir-to-flat/fixture/apply-dir-to-flat-fix.js
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 @@ | ||
const scriptsConfig = await matchToFlatDir(__dirname, 'scripts'); | ||
|
||
const monoConfig = await mergeESLintConfigs(__dirname, ['codemods', 'packages', 'rules']); |
3 changes: 3 additions & 0 deletions
3
packages/plugin-eslint/lib/apply-dir-to-flat/fixture/apply-dir-to-flat.js
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 @@ | ||
const scriptsConfig = await matchToFlatDir('scripts'); | ||
|
||
const monoConfig = await mergeESLintConfigs(['codemods', 'packages', 'rules']); |
4 changes: 4 additions & 0 deletions
4
packages/plugin-eslint/lib/apply-dir-to-flat/fixture/esm-fix.js
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,4 @@ | ||
import {matchToFlatDir} from '@putout/eslint-flat'; | ||
|
||
const scriptsConfig = await matchToFlatDir(import.meta.url, 'scripts'); | ||
const monoConfig = await mergeESLintConfigs(import.meta.url, ['codemods', 'packages', 'rules']); |
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,4 @@ | ||
import {matchToFlatDir} from '@putout/eslint-flat'; | ||
|
||
const scriptsConfig = await matchToFlatDir('scripts'); | ||
const monoConfig = await mergeESLintConfigs(['codemods', 'packages', 'rules']); |
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,18 @@ | ||
'use strict'; | ||
|
||
const {operator} = require('putout'); | ||
const {isESM} = operator; | ||
const createName = (a) => isESM(a) ? 'import.meta.url' : '__dirname'; | ||
|
||
module.exports.report = () => `Use 'if condition' instead of 'ternary expression'`; | ||
|
||
module.exports.replace = () => ({ | ||
'matchToFlatDir(__a)': (vars, path) => { | ||
const name = createName(path); | ||
return `matchToFlatDir(${name}, __a)`; | ||
}, | ||
'mergeESLintConfigs(__a)': (vars, path) => { | ||
const name = createName(path); | ||
return `mergeESLintConfigs(${name}, __a)`; | ||
}, | ||
}); |
26 changes: 26 additions & 0 deletions
26
packages/plugin-eslint/lib/apply-dir-to-flat/index.spec.js
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,26 @@ | ||
'use strict'; | ||
|
||
const {createTest} = require('@putout/test'); | ||
const plugin = require('.'); | ||
|
||
const test = createTest(__dirname, { | ||
printer: 'putout', | ||
plugins: [ | ||
['apply-dir-to-flat', plugin], | ||
], | ||
}); | ||
|
||
test('eslint: apply-dir-to-flat: report', (t) => { | ||
t.report('apply-dir-to-flat', `Use 'if condition' instead of 'ternary expression'`); | ||
t.end(); | ||
}); | ||
|
||
test('eslint: apply-dir-to-flat: transform', (t) => { | ||
t.transform('apply-dir-to-flat'); | ||
t.end(); | ||
}); | ||
|
||
test('eslint: apply-dir-to-flat: transform: esm', (t) => { | ||
t.transform('esm'); | ||
t.end(); | ||
}); |
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 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,6 @@ | ||
import {matchToFlat} from '@putout/eslint-flat'; | ||
import {mergeESLintConfigs} from '@putout/eslint-flat'; | ||
|
||
const scriptsConfig = await matchToFlatDir(__dirname, 'scripts'); | ||
|
||
const monoConfig = await mergeESLintConfigs(import.meta.url, ['codemods', 'packages', 'rules']); |
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 @@ | ||
const scriptsConfig = await matchToFlatDir('scripts'); | ||
|
||
const monoConfig = await mergeESLintConfigs(['codemods', 'packages', 'rules']); |