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

eslintignore #101

Closed
calebeby opened this issue Sep 4, 2017 · 5 comments
Closed

eslintignore #101

calebeby opened this issue Sep 4, 2017 · 5 comments

Comments

@calebeby
Copy link

calebeby commented Sep 4, 2017

Hi,

It would be awesome if prettier-eslint would support ignoring files in the eslintIgnore field in the package.json

Here's the relevant docs: https://eslint.org/docs/user-guide/configuring#using-eslintignore-in-packagejson

@kentcdodds
Copy link
Member

Thanks for the idea! Sounds like that'd be useful! Feel free to make a pull request 😀

@calebeby
Copy link
Author

calebeby commented Sep 4, 2017

I figured you'd ask 😄
I looked at the code a bit, can you point me to which function I should add the logic to?

@kentcdodds
Copy link
Member

Relevant code here:

function isFilePathMatchedByEslintignore(filePath) {
const eslintignorePath = getNearestEslintignorePath(filePath)
if (!eslintignorePath) {
return false
}
const eslintignoreDir = path.parse(eslintignorePath).dir
const filePathRelativeToEslintignoreDir = path.relative(
eslintignoreDir,
filePath,
)
const isIgnored = getIsIgnoredMemoized(eslintignorePath)
return isIgnored(filePathRelativeToEslintignoreDir)
}

Similar tests are here:

test('wont modify a file if it is eslint ignored', async () => {
await formatFiles({_: ['src/**/ignored*.js'], write: true})
expect(fsMock.readFile).toHaveBeenCalledTimes(1)
expect(fsMock.writeFile).toHaveBeenCalledTimes(1)
expect(fsMock.readFile).toHaveBeenCalledWith(
expect.stringMatching(/applied/),
'utf8',
expect.any(Function),
)
expect(fsMock.writeFile).toHaveBeenCalledWith(
expect.stringMatching(/applied/),
expect.stringMatching(/MOCK_OUTPUT.*?applied/),
expect.any(Function),
)
const ignoredOutput = expect.stringMatching(/success.*1.*file/)
expect(console.error).toHaveBeenCalledWith(ignoredOutput)
})
test('will modify a file if it is eslint ignored with noIgnore', async () => {
await formatFiles({
_: ['src/**/ignored*.js'],
write: true,
eslintIgnore: false,
})
expect(fsMock.readFile).toHaveBeenCalledTimes(4)
expect(fsMock.writeFile).toHaveBeenCalledTimes(4)
const ignoredOutput = expect.stringMatching(/success.*4.*files/)
expect(console.error).toHaveBeenCalledWith(ignoredOutput)
})
test('will not blow up if an .eslintignore cannot be found', async () => {
const originalSync = findUpMock.sync
findUpMock.sync = () => null
try {
await formatFiles({
_: ['src/**/no-eslint-ignore/*.js'],
write: true,
})
} catch (error) {
throw error
} finally {
findUpMock.sync = originalSync
}
})

Good luck! And thanks :)

@calebeby
Copy link
Author

I realized you were right about not needing this project, so I'm not going to create a PR for this. Feel free to close this if you want, or just let it open.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 8, 2021

Stale issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants