-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #170 from NullVoxPopuli/fix-typescript-prettier-co…
…mpat Compat with TypeScript's declare syntax (+ prettier)
- Loading branch information
Showing
10 changed files
with
198 additions
and
70 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
module.exports = { | ||
env: { | ||
es2021: true, | ||
}, | ||
plugins: ['@typescript-eslint', 'prettier', 'decorator-position'], | ||
parser: '@typescript-eslint/parser', | ||
extends: [ | ||
'plugin:@typescript-eslint/recommended', | ||
'plugin:decorator-position/ember', | ||
'prettier', | ||
'prettier/@typescript-eslint', | ||
], | ||
parserOptions: { | ||
ecmaFeatures: { | ||
jsx: true, | ||
}, | ||
ecmaVersion: 2018, | ||
sourceType: 'module', | ||
}, | ||
rules: { | ||
'@typescript-eslint/no-explicit-any': ['error'], | ||
'prettier/prettier': [ | ||
'error', | ||
{ | ||
singleQuote: true, | ||
printWidth: 100, | ||
semi: true, | ||
trailingComma: 'es5', | ||
quoteProps: 'preserve', | ||
}, | ||
], | ||
}, | ||
}; |
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,13 @@ | ||
type Service = unknown; | ||
|
||
function service(name) { | ||
return function decorator(target: unknown, key: string, descriptor?: PropertyDescriptor): void { | ||
console.log(target, key, descriptor); | ||
}; | ||
} | ||
export default class Foo { | ||
@service('addon-name/-private/do-not-use/the-name-of-the-service') | ||
declare someObfuscatedPrivateService: Service; | ||
|
||
@service('addon-name/-private/do-not-use/the-name-of-the-service') declare shortName: Service; | ||
} |
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,15 @@ | ||
{ | ||
"name": "test", | ||
"version": "0.0.0", | ||
"description": "smoke-test", | ||
"license": "MIT", | ||
"private": true, | ||
"dependencies": { | ||
"@typescript-eslint/parser": "*", | ||
"@typescript-eslint/eslint-plugin": "*", | ||
"eslint-plugin-decorator-position": "*", | ||
"eslint": "*", | ||
"eslint-plugin-prettier": "*", | ||
"eslint-config-prettier": "*" | ||
} | ||
} |
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,64 @@ | ||
//------------------------------------------------------------------------------ | ||
// Requirements | ||
//------------------------------------------------------------------------------ | ||
|
||
const tsParser = require.resolve('@typescript-eslint/parser'); | ||
|
||
const { stripIndent } = require('common-tags'); | ||
const RuleTester = require('eslint').RuleTester; | ||
|
||
const rule = require('../../../lib/rules/decorator-position'); | ||
// const { ERROR_MESSAGE } = rule; | ||
|
||
//------------------------------------------------------------------------------ | ||
// Tests | ||
//------------------------------------------------------------------------------ | ||
|
||
const tsRuleTester = new RuleTester({ parser: tsParser }); | ||
|
||
tsRuleTester.run('TS: decorator-position', rule, { | ||
valid: [ | ||
{ | ||
code: stripIndent` | ||
export default class LocaleSwitcher extends Component<IArgs> { | ||
@service locale!: LocaleService; | ||
} | ||
`, | ||
options: [{ overrides: { 'prefer-inline': ['@service'] } }], | ||
}, | ||
{ | ||
code: stripIndent` | ||
export default class Foo { | ||
// Would be 113 characters inline | ||
@service('addon-name/-private/do-not-use/the-name-of-the-service') | ||
declare someObfuscatedPrivateService: Service; | ||
// 96 characters | ||
@service('addon-name/-private/do-not-use/the-name-of-the-service') declare shorterName: Service; | ||
// Would be 115 characters inline | ||
@service('addon-name/-private/do-not-use/the-name-of-the-service') | ||
declare someObfuscatedPrivateService2:! Service; | ||
} | ||
`, | ||
options: [{ printWidth: 100 }], | ||
}, | ||
], | ||
invalid: [ | ||
{ | ||
code: stripIndent` | ||
export default class LocaleSwitcher extends Component<IArgs> { | ||
@service | ||
locale!: LocaleService; | ||
} | ||
`, | ||
options: [{ overrides: { 'prefer-inline': ['@service'] } }], | ||
errors: [{ message: 'Expected @service to be inline.' }], | ||
output: stripIndent` | ||
export default class LocaleSwitcher extends Component<IArgs> { | ||
@service locale!: LocaleService; | ||
} | ||
`, | ||
}, | ||
], | ||
}); |
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