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

Set eslint-plugin/consistent-output lint rule to always require test case output assertions (internal only) #1629

Merged
merged 1 commit into from
Jan 27, 2020
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
3 changes: 1 addition & 2 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@ rules:
- allowTemplateLiterals: true
avoidEscape: true

eslint-plugin/consistent-output: "error"
eslint-plugin/consistent-output: ["error", "always"]
eslint-plugin/meta-property-ordering: "error"
eslint-plugin/no-deprecated-context-methods: "error"
eslint-plugin/no-deprecated-report-api: "off"
eslint-plugin/prefer-output-null: "error"
eslint-plugin/prefer-replace-text: "error"
eslint-plugin/report-message-format: "error"
eslint-plugin/require-meta-schema: "error"
Expand Down
83 changes: 83 additions & 0 deletions tests/src/rules/dynamic-import-chunkname.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ ruleTester.run('dynamic-import-chunkname', rule, {
)`,
options,
parser,
output: `import(
// webpackChunkName: "someModule"
'someModule'
)`,
errors: [{
message: nonBlockCommentError,
type: 'CallExpression',
Expand All @@ -163,6 +167,7 @@ ruleTester.run('dynamic-import-chunkname', rule, {
code: 'import(\'test\')',
options,
parser,
output: 'import(\'test\')',
errors: [{
message: noLeadingCommentError,
type: 'CallExpression',
Expand All @@ -175,6 +180,10 @@ ruleTester.run('dynamic-import-chunkname', rule, {
)`,
options,
parser,
output: `import(
/* webpackChunkName: someModule */
'someModule'
)`,
errors: [{
message: invalidSyntaxCommentError,
type: 'CallExpression',
Expand All @@ -187,6 +196,10 @@ ruleTester.run('dynamic-import-chunkname', rule, {
)`,
options,
parser,
output: `import(
/* webpackChunkName: 'someModule' */
'someModule'
)`,
errors: [{
message: commentFormatError,
type: 'CallExpression',
Expand All @@ -199,6 +212,10 @@ ruleTester.run('dynamic-import-chunkname', rule, {
)`,
options,
parser,
output: `import(
/* webpackChunkName "someModule" */
'someModule'
)`,
errors: [{
message: invalidSyntaxCommentError,
type: 'CallExpression',
Expand All @@ -211,6 +228,10 @@ ruleTester.run('dynamic-import-chunkname', rule, {
)`,
options,
parser,
output: `import(
/* webpackChunkName:"someModule" */
'someModule'
)`,
errors: [{
message: commentFormatError,
type: 'CallExpression',
Expand All @@ -223,6 +244,10 @@ ruleTester.run('dynamic-import-chunkname', rule, {
)`,
options,
parser,
output: `import(
/*webpackChunkName: "someModule"*/
'someModule'
)`,
errors: [{
message: noPaddingCommentError,
type: 'CallExpression',
Expand All @@ -235,6 +260,10 @@ ruleTester.run('dynamic-import-chunkname', rule, {
)`,
options,
parser,
output: `import(
/* webpackChunkName : "someModule" */
'someModule'
)`,
errors: [{
message: commentFormatError,
type: 'CallExpression',
Expand All @@ -247,6 +276,10 @@ ruleTester.run('dynamic-import-chunkname', rule, {
)`,
options,
parser,
output: `import(
/* webpackChunkName: "someModule" ; */
'someModule'
)`,
errors: [{
message: invalidSyntaxCommentError,
type: 'CallExpression',
Expand All @@ -259,6 +292,10 @@ ruleTester.run('dynamic-import-chunkname', rule, {
)`,
options,
parser,
output: `import(
/* totally not webpackChunkName: "someModule" */
'someModule'
)`,
errors: [{
message: invalidSyntaxCommentError,
type: 'CallExpression',
Expand All @@ -272,6 +309,11 @@ ruleTester.run('dynamic-import-chunkname', rule, {
)`,
options,
parser,
output: `import(
/* webpackPrefetch: true */
/* webpackChunk: "someModule" */
'someModule'
)`,
errors: [{
message: commentFormatError,
type: 'CallExpression',
Expand All @@ -284,6 +326,10 @@ ruleTester.run('dynamic-import-chunkname', rule, {
)`,
options,
parser,
output: `import(
/* webpackPrefetch: true, webpackChunk: "someModule" */
'someModule'
)`,
errors: [{
message: commentFormatError,
type: 'CallExpression',
Expand All @@ -296,6 +342,10 @@ ruleTester.run('dynamic-import-chunkname', rule, {
)`,
options: pickyCommentOptions,
parser,
output: `import(
/* webpackChunkName: "someModule123" */
'someModule'
)`,
errors: [{
message: pickyCommentFormatError,
type: 'CallExpression',
Expand All @@ -307,6 +357,10 @@ ruleTester.run('dynamic-import-chunkname', rule, {
'someModule'
)`,
options: multipleImportFunctionOptions,
output: `dynamicImport(
/* webpackChunkName "someModule" */
'someModule'
)`,
errors: [{
message: invalidSyntaxCommentError,
type: 'CallExpression',
Expand All @@ -318,6 +372,10 @@ ruleTester.run('dynamic-import-chunkname', rule, {
'someModule'
)`,
options: multipleImportFunctionOptions,
output: `definitelyNotStaticImport(
/* webpackChunkName "someModule" */
'someModule'
)`,
errors: [{
message: invalidSyntaxCommentError,
type: 'CallExpression',
Expand All @@ -329,6 +387,10 @@ ruleTester.run('dynamic-import-chunkname', rule, {
'someModule'
)`,
options,
output: `dynamicImport(
// webpackChunkName: "someModule"
'someModule'
)`,
errors: [{
message: nonBlockCommentError,
type: 'CallExpression',
Expand All @@ -337,6 +399,7 @@ ruleTester.run('dynamic-import-chunkname', rule, {
{
code: 'dynamicImport(\'test\')',
options,
output: 'dynamicImport(\'test\')',
errors: [{
message: noLeadingCommentError,
type: 'CallExpression',
Expand All @@ -348,6 +411,10 @@ ruleTester.run('dynamic-import-chunkname', rule, {
'someModule'
)`,
options,
output: `dynamicImport(
/* webpackChunkName: someModule */
'someModule'
)`,
errors: [{
message: invalidSyntaxCommentError,
type: 'CallExpression',
Expand All @@ -359,6 +426,10 @@ ruleTester.run('dynamic-import-chunkname', rule, {
'someModule'
)`,
options,
output: `dynamicImport(
/* webpackChunkName: 'someModule' */
'someModule'
)`,
errors: [{
message: commentFormatError,
type: 'CallExpression',
Expand All @@ -370,6 +441,10 @@ ruleTester.run('dynamic-import-chunkname', rule, {
'someModule'
)`,
options,
output: `dynamicImport(
/* webpackChunkName "someModule" */
'someModule'
)`,
errors: [{
message: invalidSyntaxCommentError,
type: 'CallExpression',
Expand All @@ -381,6 +456,10 @@ ruleTester.run('dynamic-import-chunkname', rule, {
'someModule'
)`,
options,
output: `dynamicImport(
/* webpackChunkName:"someModule" */
'someModule'
)`,
errors: [{
message: commentFormatError,
type: 'CallExpression',
Expand All @@ -392,6 +471,10 @@ ruleTester.run('dynamic-import-chunkname', rule, {
'someModule'
)`,
options: pickyCommentOptions,
output: `dynamicImport(
/* webpackChunkName: "someModule123" */
'someModule'
)`,
errors: [{
message: pickyCommentFormatError,
type: 'CallExpression',
Expand Down
21 changes: 13 additions & 8 deletions tests/src/rules/no-commonjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,36 +68,41 @@ ruleTester.run('no-commonjs', require('rules/no-commonjs'), {

// imports
...(semver.satisfies(eslintPkg.version, '< 4.0.0') ? [] : [
{ code: 'var x = require("x")', errors: [ { message: IMPORT_MESSAGE }] },
{ code: 'x = require("x")', errors: [ { message: IMPORT_MESSAGE }] },
{ code: 'require("x")', errors: [ { message: IMPORT_MESSAGE }] },
{ code: 'var x = require("x")', output: 'var x = require("x")', errors: [ { message: IMPORT_MESSAGE }] },
{ code: 'x = require("x")', output: 'x = require("x")', errors: [ { message: IMPORT_MESSAGE }] },
{ code: 'require("x")', output: 'require("x")', errors: [ { message: IMPORT_MESSAGE }] },

{ code: 'if (typeof window !== "undefined") require("x")',
options: [{ allowConditionalRequire: false }],
output: 'if (typeof window !== "undefined") require("x")',
errors: [ { message: IMPORT_MESSAGE }],
},
{ code: 'if (typeof window !== "undefined") { require("x") }',
options: [{ allowConditionalRequire: false }],
output: 'if (typeof window !== "undefined") { require("x") }',
errors: [ { message: IMPORT_MESSAGE }],
},
{ code: 'try { require("x") } catch (error) {}',
options: [{ allowConditionalRequire: false }],
output: 'try { require("x") } catch (error) {}',
errors: [ { message: IMPORT_MESSAGE }],
},
]),

// exports
{ code: 'exports.face = "palm"', errors: [ { message: EXPORT_MESSAGE }] },
{ code: 'module.exports.face = "palm"', errors: [ { message: EXPORT_MESSAGE }] },
{ code: 'module.exports = face', errors: [ { message: EXPORT_MESSAGE }] },
{ code: 'exports = module.exports = {}', errors: [ { message: EXPORT_MESSAGE }] },
{ code: 'var x = module.exports = {}', errors: [ { message: EXPORT_MESSAGE }] },
{ code: 'exports.face = "palm"', output: 'exports.face = "palm"', errors: [ { message: EXPORT_MESSAGE }] },
{ code: 'module.exports.face = "palm"', output: 'module.exports.face = "palm"', errors: [ { message: EXPORT_MESSAGE }] },
{ code: 'module.exports = face', output: 'module.exports = face', errors: [ { message: EXPORT_MESSAGE }] },
{ code: 'exports = module.exports = {}', output: 'exports = module.exports = {}', errors: [ { message: EXPORT_MESSAGE }] },
{ code: 'var x = module.exports = {}', output: 'var x = module.exports = {}', errors: [ { message: EXPORT_MESSAGE }] },
{ code: 'module.exports = {}',
options: ['allow-primitive-modules'],
output: 'module.exports = {}',
errors: [ { message: EXPORT_MESSAGE }],
},
{ code: 'var x = module.exports',
options: ['allow-primitive-modules'],
output: 'var x = module.exports',
errors: [ { message: EXPORT_MESSAGE }],
},
],
Expand Down
1 change: 1 addition & 0 deletions tests/src/rules/unambiguous.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ ruleTester.run('unambiguous', rule, {
{
code: 'function x() {}',
parserOptions: { ecmaVersion: 2015, sourceType: 'module' },
output: 'function x() {}',
errors: ['This module could be parsed as a valid script.'],
},
],
Expand Down