Skip to content

Commit

Permalink
ESlint rules fixes (#2229)
Browse files Browse the repository at this point in the history
* fix

* fix

* fix

---------

Co-authored-by: Dimitri POSTOLOV <dmytropostolov@gmail.com>
  • Loading branch information
TuvalSimha and dimaMachina authored Feb 7, 2023
1 parent 98b95c2 commit d893a71
Show file tree
Hide file tree
Showing 17 changed files with 37 additions and 62 deletions.
12 changes: 2 additions & 10 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,17 @@ module.exports = {
files: ['**'],
rules: {
// TODO: enable following rules
'@typescript-eslint/no-namespace': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/ban-types': 'off',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-var-requires': 'off',
'n/no-restricted-import': 'off',
'yml/no-empty-mapping-value': 'off',
'no-undef': 'off',
'unicorn/prefer-node-protocol': 'off',
'no-restricted-syntax': 'off',
'no-implicit-coercion': 'off',
'import/extensions': 'off',
'no-console': 'off',
'import/no-default-export': 'off',
'no-prototype-builtins': 'off',
'unicorn/no-useless-fallback-in-spread': 'off',
'no-empty': 'off',
'n/no-restricted-import': 'off',
'no-inner-declarations': 'off',
},
},
Expand Down
4 changes: 1 addition & 3 deletions example/schemas/schema.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
const { readFileSync } = require('fs');
const { resolve } = require('path');

module.exports = readFileSync(resolve(__dirname, './schema.graphql'), {
encoding: 'utf-8',
});
module.exports = readFileSync(resolve(__dirname, './schema.graphql'), 'utf8');
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { pathsToModuleNameMapper } = require('ts-jest/utils');
const ROOT_DIR = __dirname;
const TSCONFIG = resolve(ROOT_DIR, 'tsconfig.json');
const tsconfig = require(TSCONFIG);
const CI = !!process.env.CI;
const CI = Boolean(process.env.CI);

module.exports = {
transform: { '^.+\\.tsx?$': 'ts-jest' },
Expand Down
9 changes: 3 additions & 6 deletions packages/action/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async function getAssociatedPullRequest(octokit: OctokitInstance, commitSha: str
format: 'json',
previews: ['groot'],
}
})
})
return result.data.length > 0 ? result.data[0] : null
}

Expand Down Expand Up @@ -195,7 +195,7 @@ export async function run() {
let annotations = action.annotations || [];
const changes = action.changes || [];

core.setOutput('changes', `${changes.length || 0}`);
core.setOutput('changes', String(changes.length || 0));
core.info(`Changes: ${changes.length || 0}`);

const hasApprovedBreakingChangeLabel = pullRequest?.labels?.some(
Expand Down Expand Up @@ -274,11 +274,8 @@ function fileLoader({
workspace?: string;
}): Promise<string> {
if (file.workspace) {
return readFileSync(resolve(file.workspace, file.path), {
encoding: 'utf-8',
});
return readFileSync(resolve(file.workspace, file.path), 'utf8');
}

const result: any = await octokit.graphql(query, {
repo,
owner,
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const config = require('../../jest.config');
import config from '../../jest.config';

module.exports = config;
export default config;
11 changes: 4 additions & 7 deletions packages/commands/coverage/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@ export function handler({
}

if (output) {
writeFileSync(absPath, output, {
encoding: 'utf-8',
});

writeFileSync(absPath, output, 'utf8');
Logger.success(`Available at ${absPath}\n`);
} else {
throw new Error(`Extension ${ext} is not supported`);
Expand Down Expand Up @@ -137,19 +134,19 @@ function renderCoverage(coverage: SchemaCoverage) {
Logger.info('Schema coverage based on documents:\n');

for (const typeName in coverage.types) {
if (coverage.types.hasOwnProperty(typeName)) {
if (Object.prototype.hasOwnProperty.call(coverage.types, typeName)) {
const typeCoverage = coverage.types[typeName];

Logger.log(
[
chalk.grey(getTypePrefix(typeCoverage.type)),
chalk.bold(`${typeName}`),
chalk.bold(String(typeName)),
chalk.grey('{'),
].join(' '),
);

for (const childName in typeCoverage.children) {
if (typeCoverage.children.hasOwnProperty(childName)) {
if (Object.prototype.hasOwnProperty.call(typeCoverage.children, childName)) {
const childCoverage = typeCoverage.children[childName];

if (childCoverage.hits) {
Expand Down
9 changes: 4 additions & 5 deletions packages/commands/diff/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,12 @@ export default createCommand<
const { headers, leftHeaders, rightHeaders, token } = parseGlobalArgs(args);

const oldSchemaHeaders = {
...(headers ?? {}),
...(leftHeaders ?? {}),
...headers,
...leftHeaders,
};
const newSchemaHeaders = {
...(headers ?? {}),
...(rightHeaders ?? {}),
...headers,
...rightHeaders,
};

const oldSchema = await loaders.loadSchema(
Expand Down Expand Up @@ -254,7 +254,6 @@ function resolveUsageHandler(name: string): UsageHandler | never {
} catch (error) {
throw new Error(`UsageHandler '${name}' does not exist!`);
}

const mod = require(filepath);

return mod?.default || mod;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ describe('introspect', () => {
spyReporter.mockRestore();
try {
unlinkSync('graphql.schema.json');
} catch (e) {}
} catch {
/* ignore */
}
});

test('graphql api with port and ws in name using url-loader', async () => {
Expand All @@ -85,10 +87,7 @@ describe('introspect', () => {

done();
expect(existsSync('schema.graphql')).toBe(true);

const printed = readFileSync('schema.graphql', {
encoding: 'utf-8',
});
const printed = readFileSync('schema.graphql', 'utf8');
unlinkSync('schema.graphql');

const builtSchema = buildSchema(printed);
Expand All @@ -111,10 +110,7 @@ describe('introspect', () => {

done();
expect(existsSync('schema.graphql')).toBe(true);

const printed = readFileSync('schema.graphql', {
encoding: 'utf-8',
});
const printed = readFileSync('schema.graphql', 'utf8');
unlinkSync('schema.graphql');

const builtSchema = buildSchema(printed);
Expand Down
4 changes: 1 addition & 3 deletions packages/commands/introspect/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ export function handler({
throw new Error('Only .graphql, .gql and .json files are supported');
}

writeFileSync(output, content!, {
encoding: 'utf-8',
});
writeFileSync(output, content!, 'utf8');

Logger.success(`Saved to ${filepath}`);
}
Expand Down
9 changes: 3 additions & 6 deletions packages/commands/similar/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function handler({
Logger.info('No similar types found');
} else {
for (const typeName in similarMap) {
if (similarMap.hasOwnProperty(typeName)) {
if (Object.prototype.hasOwnProperty.call(similarMap, typeName)) {
const matches = similarMap[typeName];
const prefix = getTypePrefix(schema.getType(typeName) as GraphQLNamedType);
const sourceType = chalk.bold(typeName);
Expand Down Expand Up @@ -63,10 +63,7 @@ export function handler({
}

if (output) {
writeFileSync(absPath, output, {
encoding: 'utf-8',
});

writeFileSync(absPath, output, 'utf8');
Logger.success(`Available at ${absPath}\n`);
} else {
throw new Error(`Extension ${ext} is not supported`);
Expand Down Expand Up @@ -156,7 +153,7 @@ function transformMap(similarMap: SimilarMap): SimilarResults {
const results: SimilarResults = {};

for (const typename in similarMap) {
if (similarMap.hasOwnProperty(typename)) {
if (Object.prototype.hasOwnProperty.call(similarMap, typename)) {
const result = similarMap[typename];

results[typename] = [];
Expand Down
4 changes: 1 addition & 3 deletions packages/commands/validate/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,7 @@ export function handler({
null,
2,
),
{
encoding: 'utf-8',
},
'utf8',
);
}

Expand Down
4 changes: 2 additions & 2 deletions packages/core/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const config = require('../../jest.config');
import config from '../../jest.config';

module.exports = config;
export default config;
1 change: 1 addition & 0 deletions packages/github/__tests__/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createConfig } from '../src/helpers/config';

// eslint-disable-next-line @typescript-eslint/no-empty-function
const dummySetConfig = () => {};
describe('multiple environments', () => {
describe('when branch matches environment', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/github/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const config = require('../../jest.config');
import config from '../../jest.config';

module.exports = config;
export default config;
4 changes: 2 additions & 2 deletions packages/github/src/helpers/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ function normalizeConfig(config: Config): {
const normalized: NormalizedConfig = {};

for (const envName in config.env) {
if (config.env.hasOwnProperty(envName)) {
if (Object.prototype.hasOwnProperty.call(config.env, envName)) {
const env = config.env[envName];

normalized[envName] = {
Expand Down Expand Up @@ -260,7 +260,7 @@ function findConfigByBranch(
const branches: string[] = [];

for (const name in config) {
if (config.hasOwnProperty(name)) {
if (Object.prototype.hasOwnProperty.call(config, name)) {
const env = config[name];

if (env.branch === branch) {
Expand Down
1 change: 1 addition & 0 deletions packages/github/src/schema-change-notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export async function handleSchemaChangeNotifications({
}

const branch = ref.replace('refs/heads/', '');
// eslint-disable-next-line @typescript-eslint/no-empty-function
const config = createConfig(rawConfig as any, () => {}, [branch]);

if (!config.notifications) {
Expand Down
3 changes: 2 additions & 1 deletion packages/testing/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ export function nonTTY(msg: string) {
}

declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace jest {
interface Matchers<R, T> {
interface Matchers<R> {
/**
* Strips and normalizes logs
*/
Expand Down

0 comments on commit d893a71

Please sign in to comment.