-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
baae379
commit 32d042c
Showing
47 changed files
with
154 additions
and
41 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
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
File renamed without changes.
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
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
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
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
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
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
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
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
43 changes: 43 additions & 0 deletions
43
packages/eslint-plugin-material-ui/src/rules/straight-quotes.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,43 @@ | ||
// eslint-disable-next-line material-ui/straight-quotes | ||
const nonStraightQuotes = /[‘’“”]/gm; | ||
|
||
/** | ||
* @type {import('eslint').Rule.RuleModule} | ||
*/ | ||
const rule = { | ||
meta: { | ||
docs: { | ||
description: | ||
'Only allow straight quotes. Curly quotes can still be used but in specific context where relevant.', | ||
}, | ||
messages: { | ||
wrongQuotes: | ||
'Only allow straight quotes. Curly quotes can still be used but in specific context where relevant.', | ||
}, | ||
// fixable: 'code', TODO | ||
type: 'suggestion', | ||
schema: [], | ||
}, | ||
create(context) { | ||
return { | ||
Program(node) { | ||
const value = context.sourceCode.text; | ||
let match; | ||
|
||
// eslint-disable-next-line no-cond-assign | ||
while ((match = nonStraightQuotes.exec(value)) !== null) { | ||
context.report({ | ||
node, | ||
loc: { | ||
start: context.sourceCode.getLocFromIndex(match.index), | ||
end: context.sourceCode.getLocFromIndex(match.index + 1), | ||
}, | ||
messageId: 'wrongQuotes', | ||
}); | ||
} | ||
}, | ||
}; | ||
}, | ||
}; | ||
|
||
module.exports = rule; |
63 changes: 63 additions & 0 deletions
63
packages/eslint-plugin-material-ui/src/rules/straight-quotes.test.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,63 @@ | ||
/* eslint-disable material-ui/straight-quotes */ | ||
const eslint = require('eslint'); | ||
const rule = require('./straight-quotes'); | ||
|
||
const ruleTester = new eslint.RuleTester({ parser: require.resolve('@typescript-eslint/parser') }); | ||
|
||
ruleTester.run('straight-quotes', rule, { | ||
valid: [ | ||
` | ||
const values = [ | ||
{ | ||
title: 'Put community first 💙', | ||
}, | ||
]; | ||
`, | ||
], | ||
invalid: [ | ||
{ | ||
code: ` | ||
const values = [ | ||
{ | ||
title: 'Put community first 💙', | ||
description: 'We never lose sight of who we’re serving and why.', | ||
}, | ||
]; | ||
`, | ||
errors: [ | ||
{ | ||
messageId: 'wrongQuotes', | ||
line: 5, | ||
}, | ||
], | ||
}, | ||
{ | ||
code: ` | ||
// reference ID (also known as “SHA” or “hash”) of the commit we're building. | ||
const values = 'foo'; | ||
`, | ||
errors: [ | ||
{ | ||
line: 2, | ||
column: 32, | ||
messageId: 'wrongQuotes', | ||
}, | ||
{ | ||
line: 2, | ||
column: 36, | ||
messageId: 'wrongQuotes', | ||
}, | ||
{ | ||
line: 2, | ||
column: 41, | ||
messageId: 'wrongQuotes', | ||
}, | ||
{ | ||
line: 2, | ||
column: 46, | ||
messageId: 'wrongQuotes', | ||
}, | ||
], | ||
}, | ||
], | ||
}); |
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