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
Add customSyntax
option to configuration object (#4843)
#5538
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
'use strict'; | ||
|
||
module.exports = require('postcss-safe-parser/lib/safe-parse'); | ||
module.exports = require('postcss-safe-parser'); | ||
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 |
---|---|---|
@@ -1,3 +1,8 @@ | ||
'use strict'; | ||
|
||
module.exports = require('postcss-scss/lib/scss-syntax'); | ||
const postcssScss = require('postcss-scss'); | ||
|
||
module.exports = { | ||
parse: postcssScss.parse, | ||
stringify: postcssScss.stringify, | ||
}; | ||
Comment on lines
+5
to
+8
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better represents custom syntax. |
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 |
---|---|---|
|
@@ -97,6 +97,52 @@ it('standalone with path to custom syntax', () => { | |
}); | ||
}); | ||
|
||
it('standalone with custom syntax as npm package name', () => { | ||
const config = { | ||
rules: { | ||
'block-no-empty': true, | ||
}, | ||
}; | ||
|
||
return standalone({ | ||
config, | ||
customSyntax: 'postcss-scss', | ||
code: '$foo: bar; // foo;\nb {}', | ||
formatter: stringFormatter, | ||
}).then((linted) => { | ||
const results = linted.results; | ||
|
||
expect(results).toHaveLength(1); | ||
expect(results[0].warnings).toHaveLength(1); | ||
expect(results[0].warnings[0].line).toBe(2); | ||
expect(results[0].warnings[0].column).toBe(3); | ||
expect(results[0].warnings[0].rule).toBe('block-no-empty'); | ||
}); | ||
}); | ||
|
||
it('standalone with custom syntax as npm package', () => { | ||
const config = { | ||
rules: { | ||
'block-no-empty': true, | ||
}, | ||
}; | ||
|
||
return standalone({ | ||
config, | ||
customSyntax: require('postcss-scss'), | ||
code: '$foo: bar; // foo;\nb {}', | ||
formatter: stringFormatter, | ||
}).then((linted) => { | ||
const results = linted.results; | ||
|
||
expect(results).toHaveLength(1); | ||
expect(results[0].warnings).toHaveLength(1); | ||
expect(results[0].warnings[0].line).toBe(2); | ||
expect(results[0].warnings[0].column).toBe(3); | ||
expect(results[0].warnings[0].rule).toBe('block-no-empty'); | ||
}); | ||
}); | ||
Comment on lines
+100
to
+144
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We never had these tests, but should have, as it's a documented behavior. |
||
|
||
it('rejects on unknown custom syntax option', async () => { | ||
await expect( | ||
standalone({ | ||
|
@@ -140,3 +186,111 @@ it('rejects when customSyntax and syntax are set', async () => { | |
'The "syntax" (--syntax) option has been removed. Install the appropriate syntax and use the "customSyntax" (--custom-syntax) option instead', | ||
); | ||
}); | ||
|
||
describe('customSyntax set in the config', () => { | ||
it('standalone with path to custom parser', () => { | ||
const config = { | ||
customSyntax: `${fixturesPath}/custom-parser`, | ||
rules: { | ||
'block-no-empty': true, | ||
}, | ||
}; | ||
|
||
return standalone({ | ||
config, | ||
code: '.foo { width: 200px }\n.bar {', | ||
formatter: stringFormatter, | ||
}).then((linted) => { | ||
const results = linted.results; | ||
|
||
expect(results).toHaveLength(1); | ||
expect(results[0].warnings).toHaveLength(1); | ||
expect(results[0].warnings[0].line).toBe(2); | ||
expect(results[0].warnings[0].column).toBe(6); | ||
expect(results[0].warnings[0].rule).toBe('block-no-empty'); | ||
}); | ||
}); | ||
|
||
it('standalone with custom syntax as npm package name', () => { | ||
const config = { | ||
customSyntax: 'postcss-scss', | ||
rules: { | ||
'block-no-empty': true, | ||
}, | ||
}; | ||
|
||
return standalone({ | ||
config, | ||
code: '$foo: bar; // foo;\nb {}', | ||
formatter: stringFormatter, | ||
}).then((linted) => { | ||
const results = linted.results; | ||
|
||
expect(results).toHaveLength(1); | ||
expect(results[0].warnings).toHaveLength(1); | ||
expect(results[0].warnings[0].line).toBe(2); | ||
expect(results[0].warnings[0].column).toBe(3); | ||
expect(results[0].warnings[0].rule).toBe('block-no-empty'); | ||
}); | ||
}); | ||
|
||
it('standalone with custom syntax as npm package', () => { | ||
const config = { | ||
customSyntax: require('postcss-scss'), | ||
rules: { | ||
'block-no-empty': true, | ||
}, | ||
}; | ||
|
||
return standalone({ | ||
config, | ||
code: '$foo: bar; // foo;\nb {}', | ||
formatter: stringFormatter, | ||
}).then((linted) => { | ||
const results = linted.results; | ||
|
||
expect(results).toHaveLength(1); | ||
expect(results[0].warnings).toHaveLength(1); | ||
expect(results[0].warnings[0].line).toBe(2); | ||
expect(results[0].warnings[0].column).toBe(3); | ||
expect(results[0].warnings[0].rule).toBe('block-no-empty'); | ||
}); | ||
}); | ||
|
||
it('standalone with path to custom syntax', () => { | ||
const config = { | ||
customSyntax: `${fixturesPath}/custom-syntax`, | ||
rules: { | ||
'block-no-empty': true, | ||
}, | ||
}; | ||
|
||
return standalone({ | ||
config, | ||
code: '$foo: bar; // foo;\nb {}', | ||
formatter: stringFormatter, | ||
}).then((linted) => { | ||
const results = linted.results; | ||
|
||
expect(results).toHaveLength(1); | ||
expect(results[0].warnings).toHaveLength(1); | ||
expect(results[0].warnings[0].line).toBe(2); | ||
expect(results[0].warnings[0].column).toBe(3); | ||
expect(results[0].warnings[0].rule).toBe('block-no-empty'); | ||
}); | ||
}); | ||
|
||
it('rejects on unknown custom syntax option', async () => { | ||
await expect( | ||
standalone({ | ||
code: '', | ||
config: { | ||
customSyntax: 'unknown-module', | ||
rules: { 'block-no-empty': 'wahoo' }, | ||
}, | ||
}), | ||
).rejects.toThrow( | ||
'Cannot resolve custom syntax module unknown-module. Check that module unknown-module is available and spelled correctly.', | ||
); | ||
}); | ||
}); |
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid using internals.