Skip to content

chore(*): Enable comma-dangle #271

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

Merged
merged 7 commits into from
Feb 19, 2019
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
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ node_modules
dist
jest.config.js
fixtures
shared-fixtures
coverage

packages/typescript-estree/src/estree
Expand Down
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
},
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
"rules": {
"comma-dangle": ["error", "always-multiline"],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need eslint rule for this? we are using prettier

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the lint rule gives you in-editor warnings when you're writing code (helps in case you don't have format on save turned on).
will also give a better warning in the CI logs. (the prettier check will just say the file failed formatting, whereas the eslint check will tell you the actual problem)

"no-mixed-operators": "error",
"no-console": "off",
"no-undef": "off",
Expand Down
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
**/tests/integration/fixtures/**/*
**/lib/configs/recommended.json
**/.vscode
**/.nyc_output
**/.nyc_output
packages/eslint-plugin-tslint/tests/test-tslint-rules-directory/alwaysFailRule.js
3 changes: 3 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"trailingComma": "all"
}
4 changes: 2 additions & 2 deletions packages/eslint-plugin-tslint/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
module.exports = {
testEnvironment: 'node',
transform: {
'^.+\\.tsx?$': 'ts-jest'
'^.+\\.tsx?$': 'ts-jest',
},
testRegex: './tests/.+\\.spec\\.ts$',
collectCoverage: false,
collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}'],
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
coverageReporters: ['text-summary', 'lcov']
coverageReporters: ['text-summary', 'lcov'],
};
44 changes: 22 additions & 22 deletions packages/eslint-plugin-tslint/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ const tslintConfig = memoize(
(
lintFile: string,
tslintRules: RawRulesConfig,
tslintRulesDirectory: string[]
tslintRulesDirectory: string[],
) => {
if (lintFile != null) {
return Configuration.loadConfigurationFromPath(lintFile);
}
return Configuration.parseConfigFile({
rules: tslintRules || {},
rulesDirectory: tslintRulesDirectory || []
rulesDirectory: tslintRulesDirectory || [],
});
},
(lintFile: string | undefined, tslintRules = {}, tslintRulesDirectory = []) =>
`${lintFile}_${Object.keys(tslintRules).join(',')}_${
tslintRulesDirectory.length
}`
}`,
);

export const rules = {
Expand All @@ -56,7 +56,7 @@ export const rules = {
docs: {
description:
'Wraps a TSLint configuration and lints the whole source using TSLint',
category: 'TSLint'
category: 'TSLint',
},
schema: [
{
Expand All @@ -67,21 +67,21 @@ export const rules = {
/**
* No fixed schema properties for rules, as this would be a permanently moving target
*/
additionalProperties: true
additionalProperties: true,
},
rulesDirectory: {
type: 'array',
items: {
type: 'string'
}
type: 'string',
},
},
lintFile: {
type: 'string'
}
type: 'string',
},
},
additionalProperties: false
}
]
additionalProperties: false,
},
],
},
create: function(context: Rule.RuleContext) {
const fileName = context.getFilename();
Expand All @@ -94,7 +94,7 @@ export const rules = {
*/
if (!parserServices || !parserServices.program) {
throw new Error(
`You must provide a value for the "parserOptions.project" property for @typescript-eslint/parser`
`You must provide a value for the "parserOptions.project" property for @typescript-eslint/parser`,
);
}

Expand All @@ -104,7 +104,7 @@ export const rules = {
const {
rules: tslintRules,
rulesDirectory: tslintRulesDirectory,
lintFile
lintFile,
} = context.options[0];

const program: Program = parserServices.program;
Expand All @@ -116,13 +116,13 @@ export const rules = {
*/
const tslintOptions = {
formatter: 'json',
fix: false
fix: false,
};
const tslint = new CustomLinter(tslintOptions, program);
const configuration = tslintConfig(
lintFile,
tslintRules,
tslintRulesDirectory
tslintRulesDirectory,
);
tslint.lint(fileName, sourceCode, configuration);

Expand All @@ -140,13 +140,13 @@ export const rules = {
loc: {
start: {
line: start.line + 1,
column: start.character
column: start.character,
},
end: {
line: end.line + 1,
column: end.character
}
}
column: end.character,
},
},
});
});
}
Expand All @@ -155,6 +155,6 @@ export const rules = {
* Return an empty object for the ESLint rule
*/
return {};
}
}
},
},
};
68 changes: 34 additions & 34 deletions packages/eslint-plugin-tslint/tests/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ const ruleTester = new RuleTester({
* Project is needed to generate the parserServices
* within @typescript-eslint/parser
*/
project: './tests/tsconfig.json'
project: './tests/tsconfig.json',
},
parser: '@typescript-eslint/parser'
parser: '@typescript-eslint/parser',
});

/**
* Inline rules should be supported
*/
const tslintRulesConfig = {
rules: {
semicolon: [true, 'always']
}
semicolon: [true, 'always'],
},
};

/**
Expand All @@ -32,36 +32,36 @@ const tslintRulesDirectoryConfig = {
rulesDirectory: ['./tests/test-tslint-rules-directory'],
rules: {
'always-fail': {
severity: 'error'
}
}
severity: 'error',
},
},
};

ruleTester.run('tslint/config', rules.config, {
valid: [
{
code: 'var foo = true;',
options: [tslintRulesConfig]
options: [tslintRulesConfig],
},
{
filename: './tests/test-project/file-spec.ts',
code: readFileSync('./tests/test-project/file-spec.ts', 'utf8').replace(
/\n/g,
' '
' ',
),
parserOptions: {
project: `${__dirname}/test-project/tsconfig.json`
project: `${__dirname}/test-project/tsconfig.json`,
},
options: [
{
...tslintRulesConfig
}
]
...tslintRulesConfig,
},
],
},
{
code: 'throw "should be ok because rule is not loaded";',
options: [tslintRulesConfig]
}
options: [tslintRulesConfig],
},
],

invalid: [
Expand All @@ -71,9 +71,9 @@ ruleTester.run('tslint/config', rules.config, {
errors: [
{
message:
'Throwing plain strings (not instances of Error) gives no stack traces (tslint:no-string-throw)'
}
]
'Throwing plain strings (not instances of Error) gives no stack traces (tslint:no-string-throw)',
},
],
},
{
code: 'var foo = true // semicolon',
Expand All @@ -83,9 +83,9 @@ ruleTester.run('tslint/config', rules.config, {
{
message: 'Missing semicolon (tslint:semicolon)',
line: 1,
column: 15
}
]
column: 15,
},
],
},
{
code: 'var foo = true // fail',
Expand All @@ -95,33 +95,33 @@ ruleTester.run('tslint/config', rules.config, {
{
message: 'failure (tslint:always-fail)',
line: 1,
column: 1
}
]
column: 1,
},
],
},
{
filename: './tests/test-project/source.ts',
code: readFileSync('./tests/test-project/source.ts', 'utf8').replace(
/\n/g,
' '
' ',
),
parserOptions: {
project: `${__dirname}/test-project/tsconfig.json`
project: `${__dirname}/test-project/tsconfig.json`,
},
options: [
{
rulesDirectory: [
`${__dirname}/../../../node_modules/tslint/lib/rules`
`${__dirname}/../../../node_modules/tslint/lib/rules`,
],
rules: { 'restrict-plus-operands': true }
}
rules: { 'restrict-plus-operands': true },
},
],
errors: [
{
message:
"Operands of '+' operation must either be both strings or both numbers, consider using template literals (tslint:restrict-plus-operands)"
}
]
}
]
"Operands of '+' operation must either be both strings or both numbers, consider using template literals (tslint:restrict-plus-operands)",
},
],
},
],
});
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

const Lint = require('tslint');

class Rule extends Lint.Rules.AbstractRule {
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-plugin/docs/rules/camelcase.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function foo({ no_camelcased = 'default value' }) {
}

var obj = {
my_pref: 1
my_pref: 1,
};

var { category_id = 1 } = query;
Expand Down Expand Up @@ -125,7 +125,7 @@ Examples of **correct** code for this rule with the `{ "properties": "never" }`
/*eslint @typescript-eslint/camelcase: ["error", {properties: "never"}]*/

var obj = {
my_pref: 1
my_pref: 1,
};
```

Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/docs/rules/no-extraneous-class.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const StaticOnly = {
version: 42,
hello() {
console.log('Hello, world!');
}
},
};
```

Expand Down
6 changes: 3 additions & 3 deletions packages/eslint-plugin/docs/rules/no-this-alias.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ You can pass an object option:
'error',
{
allowDestructuring: true, // Allow `const { props, state } = this`; false by default
allowedNames: ['self'] // Allow `const self = this`; `[]` by default
}
]
allowedNames: ['self'], // Allow `const self = this`; `[]` by default
},
],
}
```

Expand Down
6 changes: 3 additions & 3 deletions packages/eslint-plugin/docs/rules/no-unnecessary-qualifier.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace A {
```ts
enum A {
B,
C = A.B
C = A.B,
}
```

Expand Down Expand Up @@ -52,11 +52,11 @@ namespace Y {
```ts
enum A {
X,
Y
Y,
}

enum B {
Z = A.X
Z = A.X,
}
```

Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/docs/rules/no-unused-vars.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ alert(x);
myFunc(
function foo() {
// ...
}.bind(this)
}.bind(this),
);

(function(foo) {
Expand Down
Loading