Skip to content

chore: convert some requires to import statements #112

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

Closed
wants to merge 1 commit into from
Closed
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
7 changes: 6 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/explicit-member-accessibility": "off",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/no-object-literal-type-assertion": "off",
"@typescript-eslint/no-parameter-properties": "off"
Expand All @@ -27,6 +26,12 @@
}
},
"overrides": [
{
"files": ["packages/eslint-plugin/**/*.js"],
"rules": {
"@typescript-eslint/no-var-requires": "off"
}
},
{
"files": [
"packages/eslint-plugin-tslint/**/*.ts",
Expand Down
12 changes: 6 additions & 6 deletions packages/eslint-plugin/tools/update-recommended.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* eslint-disable no-console */
'use strict';

const path = require('path');
const fs = require('fs');
const requireIndex = require('requireindex');
import { resolve } from 'path';
import { writeFileSync } from 'fs';
import requireIndex from 'requireindex';

const bannedRecommendedRules = new Set([
'camelcase',
Expand All @@ -19,7 +19,7 @@ const MAX_RULE_NAME_LENGTH = 32 + 'typescript/'.length;
*/
function generate() {
// replace this with Object.entries when node > 8
const allRules = requireIndex(path.resolve(__dirname, '../lib/rules'));
const allRules = requireIndex(resolve(__dirname, '../lib/rules'));

const rules = Object.keys(allRules)
.filter(key => !!allRules[key].meta.docs.recommended)
Expand All @@ -46,7 +46,7 @@ function generate() {
return config;
}, {});

const filePath = path.resolve(__dirname, '../lib/configs/recommended.json');
const filePath = resolve(__dirname, '../lib/configs/recommended.json');

const recommendedConfig = {
parser: '@typescript-eslint/parser',
Expand All @@ -57,7 +57,7 @@ function generate() {
rules
};

fs.writeFileSync(filePath, `${JSON.stringify(recommendedConfig, null, 4)}\n`);
writeFileSync(filePath, `${JSON.stringify(recommendedConfig, null, 4)}\n`);
}

generate();
7 changes: 3 additions & 4 deletions packages/parser/src/parser.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import traverser from 'eslint/lib/util/traverser';
import {
AST_NODE_TYPES,
parseAndGenerateServices,
ParserOptions as ParserOptionsTsESTree
} from '@typescript-eslint/typescript-estree';
import traverser from 'eslint/lib/util/traverser';
import { Program } from 'typescript';
import packageJSON from '../package.json';
import { analyzeScope } from './analyze-scope';
import { ParserOptions } from './parser-options';
import { visitorKeys } from './visitor-keys';
import { Program } from 'typescript';

const packageJSON = require('../package.json');

interface ParserServices {
program: Program | undefined;
Expand Down
13 changes: 6 additions & 7 deletions packages/typescript-estree/src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,24 @@
* @copyright jQuery Foundation and other contributors, https://jquery.org/
* MIT License
*/
import {
calculateProjectParserOptions,
createProgram
} from './tsconfig-parser';
import semver from 'semver';
import ts from 'typescript';
import packageJSON from '../package.json';
import convert from './ast-converter';
import { convertError } from './convert';
import { Program } from './estree/spec';
import { firstDefined } from './node-utils';
import { getFirstSemanticOrSyntacticError } from './semantic-errors';
import {
ESTreeComment,
ESTreeToken,
Extra,
ParserOptions
} from './temp-types-based-on-js-source';
import { getFirstSemanticOrSyntacticError } from './semantic-errors';

const packageJSON = require('../package.json');
import {
calculateProjectParserOptions,
createProgram
} from './tsconfig-parser';

const SUPPORTED_TYPESCRIPT_VERSIONS = packageJSON.devDependencies.typescript;
const ACTIVE_TYPESCRIPT_VERSION = ts.version;
Expand Down
3 changes: 2 additions & 1 deletion packages/typescript-estree/tests/ast-alignment/parse.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ParserPlugin } from '@babel/parser';
import codeFrame from 'babel-code-frame';
import * as parser from '../../src/parser';
import * as parseUtils from './utils';
import { ParserPlugin } from '@babel/parser';

function createError(message: string, line: number, column: number) {
// Construct an error similar to the ones thrown by Babylon.
Expand All @@ -14,6 +14,7 @@ function createError(message: string, line: number, column: number) {
}

function parseWithBabelParser(text: string, jsx: boolean = true) {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const babel = require('@babel/parser');
const plugins: ParserPlugin[] = [
'typescript',
Expand Down
12 changes: 6 additions & 6 deletions tests/integration/utils/generate-package-json.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const fs = require('fs');
const rootPackageJSON = require('/usr/root-package.json');
import { writeFileSync } from 'fs';
import { devDependencies } from '/usr/root-package.json';

/**
* Apply package versions based on what they are currently set to in the root package.json
Expand All @@ -8,9 +8,9 @@ const rootPackageJSON = require('/usr/root-package.json');
const testPackageJSON = {
private: true,
devDependencies: {
eslint: rootPackageJSON.devDependencies.eslint,
typescript: rootPackageJSON.devDependencies.typescript,
tslint: rootPackageJSON.devDependencies.tslint,
eslint: devDependencies.eslint,
typescript: devDependencies.typescript,
tslint: devDependencies.tslint,
/**
* TEMP: Bump jest to ahead of our stable usage in the monorepo,
* we need the bleeding edge snapshotResolver option
Expand All @@ -20,4 +20,4 @@ const testPackageJSON = {
}
};

fs.writeFileSync('/usr/package.json', JSON.stringify(testPackageJSON, null, 2));
writeFileSync('/usr/package.json', JSON.stringify(testPackageJSON, null, 2));
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"target": "es2017",
"module": "commonjs",
"moduleResolution": "node",
"resolveJsonModule": true,
"esModuleInterop": true,
"strict": true
}
Expand Down