Skip to content

Commit

Permalink
Merge pull request #623 from Galooshi/eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
lencioni authored Jun 10, 2024
2 parents 5dd8ab4 + bc3bd79 commit ece0e66
Show file tree
Hide file tree
Showing 31 changed files with 523 additions and 912 deletions.
3 changes: 1 addition & 2 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"presets": ["@babel/preset-react", "@babel/preset-env", "@babel/preset-flow"],
"presets": ["@babel/preset-react", "@babel/preset-env"],
"plugins": [
"@babel/plugin-transform-flow-strip-types",
"@babel/plugin-proposal-class-properties",
"@babel/plugin-transform-runtime"
]
Expand Down
2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

22 changes: 22 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: ESLint

on: [push]

jobs:
eslint:
name: ESLint
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 20

- name: Install dependencies
run: npm ci

- name: Run ESLint
run: npm run eslint
23 changes: 23 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import globals from 'globals';
import pluginJs from '@eslint/js';

export default [
{
ignores: ['build/**', 'coverage/**'],
},

{
languageOptions: {
globals: globals.node,
},
},

pluginJs.configs.recommended,

{
files: ['**/__mocks__/**', '**/__tests__/**'],
languageOptions: {
globals: globals.jest,
},
},
];
14 changes: 7 additions & 7 deletions lib/CommandLineEditor.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
// @flow
//
export default class CommandLineEditor {
_lines: Array<string>;
_lines;

constructor(lines: Array<string>) {
constructor(lines) {
this._lines = lines;
}

currentFileContent(): string {
currentFileContent() {
return this._lines.join('\n');
}

get(index: number): string {
get(index) {
return this._lines[index];
}

remove(index: number) {
remove(index) {
this._lines.splice(index, 1);
}

/**
* Insert a line above the specified index
*/
insertBefore(index: number, str: string) {
insertBefore(index, str) {
this._lines.splice(index, 0, str);
}
}
59 changes: 22 additions & 37 deletions lib/Configuration.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @flow
//

import os from 'os';
import path from 'path';
Expand Down Expand Up @@ -26,16 +26,16 @@ const ENVIRONMENTS = {
meteor: meteorEnvironment,
};

function checkConfiguration(config: Object): Array<string> {
function checkConfiguration(config) {
const result = validate(config);

return result.messages;
}

function checkForDeprecatedConfiguration(config: Object): Array<string> {
function checkForDeprecatedConfiguration(config) {
const messages = [];

Object.keys(config).forEach((option: string) => {
Object.keys(config).forEach((option) => {
if (DEPRECATED_CONFIGURATION_OPTIONS.indexOf(option) !== -1) {
messages.push(
`Using ${option} to configure ImportJS is deprecated and ` +
Expand All @@ -53,7 +53,7 @@ function checkForDeprecatedConfiguration(config: Object): Array<string> {
* @throws Error if current version is less than the `minimumVersion` defined
* in config.
*/
function checkCurrentVersion(minimumVersion: string) {
function checkCurrentVersion(minimumVersion) {
if (semver.gte(version(), minimumVersion)) {
return;
}
Expand All @@ -63,7 +63,7 @@ function checkCurrentVersion(minimumVersion: string) {
);
}

function mergedValue(values: Array<any>, key: string, options: Object): any {
function mergedValue(values, key, options) {
let mergedResult;
for (let i = 0; i < values.length; i += 1) {
let value = values[i];
Expand Down Expand Up @@ -95,7 +95,7 @@ function mergedValue(values: Array<any>, key: string, options: Object): any {
/**
* returns configuration from a JS file in home directory if it exists, or null
*/
function loadGlobalJsConfig(): ?Object {
function loadGlobalJsConfig() {
for (let i = 0; i < JS_CONFIG_FILES.length; i += 1) {
const jsConfigFile = JS_CONFIG_FILES[i];
const globalConfig = FileUtils.readJsFile(
Expand All @@ -111,18 +111,15 @@ function loadGlobalJsConfig(): ?Object {

// Class that initializes configuration from a .importjs.js file
export default class Configuration {
pathToCurrentFile: string;
pathToCurrentFile;

messages: Array<string>;
messages;

configs: Array<Object>;
configs;

workingDirectory: string;
workingDirectory;

constructor(
pathToCurrentFile: string,
workingDirectory: string = process.cwd(),
) {
constructor(pathToCurrentFile, workingDirectory = process.cwd()) {
this.workingDirectory = workingDirectory;
this.pathToCurrentFile = normalizePath(pathToCurrentFile, workingDirectory);

Expand Down Expand Up @@ -153,7 +150,7 @@ export default class Configuration {
pathToCurrentFile: this.pathToCurrentFile,
});
}
(userConfig.environments || []).forEach((environment: string) => {
(userConfig.environments || []).forEach((environment) => {
const envConfig = ENVIRONMENTS[environment];
if (envConfig) {
this.configs.push(envConfig);
Expand All @@ -166,24 +163,13 @@ export default class Configuration {
checkCurrentVersion(this.get('minimumVersion'));
}

get(
key: string,
{
pathToImportedModule,
moduleName,
importStatement,
}: {
pathToImportedModule?: string,
moduleName?: string,
importStatement?: string,
} = {},
): any {
const applyingConfigs = this.configs.filter((config: Object): boolean =>
get(key, { pathToImportedModule, moduleName, importStatement } = {}) {
const applyingConfigs = this.configs.filter((config) =>
Object.prototype.hasOwnProperty.call(config, key),
);

return mergedValue(
applyingConfigs.map((config: Object): any => config[key]),
applyingConfigs.map((config) => config[key]),
key,
{
pathToImportedModule,
Expand All @@ -195,15 +181,15 @@ export default class Configuration {
);
}

loadUserConfig(): ?Object {
loadUserConfig() {
return (
this.loadLocalJsConfig() ||
this.loadLocalJsonConfig() ||
loadGlobalJsConfig()
);
}

loadLocalJsConfig(): ?Object {
loadLocalJsConfig() {
for (let i = 0; i < JS_CONFIG_FILES.length; i += 1) {
const jsConfigFile = JS_CONFIG_FILES[i];
const jsConfig = FileUtils.readJsFile(
Expand All @@ -227,7 +213,7 @@ export default class Configuration {
return null;
}

loadLocalJsonConfig(): ?Object {
loadLocalJsonConfig() {
const jsonConfig = FileUtils.readJsonFile(
path.join(this.workingDirectory, JSON_CONFIG_FILE),
);
Expand All @@ -242,7 +228,7 @@ export default class Configuration {
return null;
}

resolveAlias(variableName: string): ?string {
resolveAlias(variableName) {
if (!has(this.get('aliases'), variableName)) {
return null;
}
Expand All @@ -264,11 +250,10 @@ export default class Configuration {
return importPath;
}

resolveNamedExports(variableName: string): ?JsModule {
resolveNamedExports(variableName) {
const allNamedExports = this.get('namedExports');
const importPath = Object.keys(allNamedExports).find(
(key: string): boolean =>
allNamedExports[key].indexOf(variableName) !== -1,
(key) => allNamedExports[key].indexOf(variableName) !== -1,
);

if (!importPath) {
Expand Down
6 changes: 3 additions & 3 deletions lib/FileUtils.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// @flow
//
import fs from 'fs';

export default {
readJsonFile(absoluteFilePath: string): ?Object {
readJsonFile(absoluteFilePath) {
if (!fs.existsSync(absoluteFilePath)) {
return null;
}
Expand All @@ -16,7 +16,7 @@ export default {
return JSON.parse(contents);
},

readJsFile(absoluteFilePath: string): ?Object {
readJsFile(absoluteFilePath) {
if (!fs.existsSync(absoluteFilePath)) {
return null;
}
Expand Down
Loading

0 comments on commit ece0e66

Please sign in to comment.