Skip to content

Commit

Permalink
Apply lint fixes. Ignore some files that can be addressed in a follow…
Browse files Browse the repository at this point in the history
… up pr
  • Loading branch information
cloke committed Nov 6, 2024
1 parent 3212a8e commit d51c156
Show file tree
Hide file tree
Showing 21 changed files with 189 additions and 153 deletions.
File renamed without changes.
4 changes: 2 additions & 2 deletions addon/utils/get-messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ let cachedRef = null;
*/
export default function getMessages(
moduleMap = requirejs.entries,
useCache = true
useCache = true,
) {
let messagesModule = defaultMessages;

Expand All @@ -36,7 +36,7 @@ export default function getMessages(
// Merge the user specified messages with the defaults
messagesModule = withDefaults(
requireModule(moduleKey).default,
messagesModule
messagesModule,
);
}

Expand Down
8 changes: 4 additions & 4 deletions addon/utils/handle-multiple-validations.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { isPromise } from 'validated-changeset';
*/
function handleValidations(validations = []) {
let rejectedValidations = emberArray(validations).reject(
(validation) => typeOf(validation) === 'boolean' && validation
(validation) => typeOf(validation) === 'boolean' && validation,
);

return rejectedValidations.length === 0 || rejectedValidations;
Expand All @@ -34,12 +34,12 @@ function handleValidations(validations = []) {
*/
export default function handleMultipleValidations(
validators,
{ key, newValue, oldValue, changes, content }
{ key, newValue, oldValue, changes, content },
) {
let validations = emberArray(
validators.map((validator) =>
validator(key, newValue, oldValue, changes, content)
)
validator(key, newValue, oldValue, changes, content),
),
);

if (emberArray(validations).any(isPromise)) {
Expand Down
3 changes: 1 addition & 2 deletions addon/utils/to-date.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ export default function toDate(argument) {
(typeof argument === 'string' || argStr === '[object String]') &&
typeof console !== 'undefined'
) {
// eslint-disable-next-line no-console
console.warn('Please use `Date.parse` to parse strings.');
// eslint-disable-next-line no-console

console.warn(new Error().stack);
}
return new Date(NaN);
Expand Down
6 changes: 3 additions & 3 deletions addon/utils/validation-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,20 @@ export default function buildMessage(key, result) {
let builtMessage = message(key, type, value, context);
assert(
'Custom message function must return a string',
typeof builtMessage === 'string'
typeof builtMessage === 'string',
);

return builtMessage;
}

return messages.formatMessage(
message,
Object.assign({ description }, context)
Object.assign({ description }, context),
);
}

return messages.formatMessage(
message,
Object.assign({ description }, context)
Object.assign({ description }, context),
);
}
53 changes: 53 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// eslint.config.mjs

import { FlatCompat } from '@eslint/eslintrc';
import emberPlugin from 'eslint-plugin-ember';
import prettierPlugin from 'eslint-plugin-prettier';
import js from '@eslint/js'; // Import ESLint core configs
import globals from 'globals'; // Import globals

const compat = new FlatCompat({
baseDirectory: import.meta.url,
resolvePluginsRelativeTo: import.meta.url,
recommendedConfig: js.configs.recommended, // Provide recommendedConfig
});

export default [
{
files: ['**/*.js'],
languageOptions: {
ecmaVersion: 'latest',
sourceType: 'module', // Ensure ES module parsing
globals: {
...globals.browser,
},
},
plugins: {
ember: emberPlugin,
prettier: prettierPlugin,
},
rules: {},
},
// Extend configurations using FlatCompat
...compat.extends(
'eslint:recommended',
'plugin:ember/recommended',
'plugin:prettier/recommended',
),
{
ignores: [
'node_modules/',
'dist/',
'blueprints',
'.prettierrc.cjs',
'.template-lintrc.js',
'config/ember-try.js',
'ember-cli-build.js',
'index.js',
'node-test/',
'config/environment.js',
'tests/dummy/',
'testem.js',
],
},
];
16 changes: 0 additions & 16 deletions node-test/.eslintrc.js

This file was deleted.

6 changes: 3 additions & 3 deletions node-test/blueprints/validator-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ describe('Acceptance: ember generate and destroy validator', function () {
return emberNew().then(() =>
emberGenerateDestroy(args, (file) => {
expect(file('app/validators/is-positive.js')).to.contain(
'export default function validateIsPositive(/* options = {} */) {\n'
'export default function validateIsPositive(/* options = {} */) {\n',
);
expect(file('tests/unit/validators/is-positive-test.js'))
.to.contain(
"import validateIsPositive from 'my-app/validators/is-positive';"
"import validateIsPositive from 'my-app/validators/is-positive';",
)
.to.contain("module('Unit | Validator | is-positive');")
.to.contain('assert.ok(validateIsPositive());');
})
}),
);
});
});
2 changes: 1 addition & 1 deletion tests/integration/components/address-book-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module('Integration | Component | address-book', function (hooks) {
return Promise.resolve();
};
await render(
hbs`<AddressBook @onSave={{this.onSave}} @model={{this.model}} />`
hbs`<AddressBook @onSave={{this.onSave}} @model={{this.model}} />`,
);

await fillIn('#address-book-name', 'abcdef');
Expand Down
18 changes: 9 additions & 9 deletions tests/integration/components/validation-errors-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,43 +50,43 @@ module('Integration | Components | validation errors', function (hooks) {
assert.strictEqual(
find('ul.lastNameErrors li').textContent.trim(),
'[CUSTOM] Last name is too short (minimum is 2 characters)',
'has last name errors'
'has last name errors',
);
assert.notOk(find('ul.ageErrors'), 'has no age errors');

await fillIn('input.lastName', 'bc');

assert.ok(
find('ul.firstNameErrors li'),
'has first name errors after last name input'
'has first name errors after last name input',
);
assert.notOk(
find('ul.lastNameErrors'),
'has no last name errors after input'
'has no last name errors after input',
);
assert.notOk(find('ul.ageErrors'), 'has no age errors');

await fillIn('input.age', '12');

assert.ok(
find('ul.firstNameErrors li'),
'has first name errors after last name input'
'has first name errors after last name input',
);
assert.notOk(
find('ul.lastNameErrors'),
'has no last name errors after input'
'has no last name errors after input',
);
assert.notOk(find('ul.ageErrors'), 'has no age errors after input');

await fillIn('input.age', '');

assert.ok(
find('ul.firstNameErrors li'),
'has first name errors after last name input'
'has first name errors after last name input',
);
assert.notOk(
find('ul.lastNameErrors'),
'has no last name errors after input'
'has no last name errors after input',
);
assert.ok(find('ul.ageErrors'), 'has age errors after input');
});
Expand Down Expand Up @@ -133,7 +133,7 @@ module('Integration | Components | validation errors', function (hooks) {
assert.strictEqual(
find('ul.stateWiErrors li').textContent.trim(),
'[CUSTOM] State wi is too short (minimum is 2 characters)',
'has last name errors'
'has last name errors',
);

await fillIn('input.state-wi', 'bc');
Expand All @@ -142,7 +142,7 @@ module('Integration | Components | validation errors', function (hooks) {
assert.strictEqual(
find('ul.stateNyErrors li').textContent.trim(),
'[CUSTOM] State ny is too short (minimum is 2 characters)',
'has last name errors'
'has last name errors',
);
assert.notOk(find('ul.stateWiErrors'), 'has no wi errors after input');
});
Expand Down
28 changes: 14 additions & 14 deletions tests/unit/helpers/changeset-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module('Unit | Helper | changeset', function () {
]);
assert.ok(
changesetInstance.get('isInvalid'),
'should be invalid with wrong length first name'
'should be invalid with wrong length first name',
);

changesetInstance.set('firstName', '');
Expand All @@ -49,24 +49,24 @@ module('Unit | Helper | changeset', function () {
]);
assert.ok(
changesetInstance.get('isInvalid'),
'should be invalid with blank first name'
'should be invalid with blank first name',
);

changesetInstance.set('lastName', '');
assert.deepEqual(
changesetInstance.get('error').lastName.validation,
"[CUSTOM] Last name can't be blank"
"[CUSTOM] Last name can't be blank",
);
assert.ok(
changesetInstance.get('isInvalid'),
'should be invalid with blank last name'
'should be invalid with blank last name',
);

changesetInstance.set('firstName', 'Jim');
changesetInstance.set('lastName', 'Bob');
assert.ok(
changesetInstance.get('isValid'),
'should be valid after setting valid first and last names'
'should be valid after setting valid first and last names',
);
});

Expand All @@ -91,15 +91,15 @@ module('Unit | Helper | changeset', function () {
assert.deepEqual(
JSON.parse(JSON.stringify(changesetInstance.get('error').email)),
expectedError,
'email should error'
'email should error',
);

changesetInstance.set('username', 'jimbob');
await settled();
assert.deepEqual(
changesetInstance.get('change').username,
'jimbob',
'should set username'
'should set username',
);

changesetInstance.set('username', 'foo@bar.com');
Expand All @@ -108,7 +108,7 @@ module('Unit | Helper | changeset', function () {
assert.deepEqual(
JSON.parse(JSON.stringify(changesetInstance.get('error').username)),
expectedError,
'username should error'
'username should error',
);
});

Expand All @@ -127,13 +127,13 @@ module('Unit | Helper | changeset', function () {
changesetInstance.set('firstName', 'Herp');
assert.ok(
changesetInstance.get('isValid'),
'should be valid if content is passed into validator'
'should be valid if content is passed into validator',
);

changesetInstance.set('lastName', 'McDerpface');
assert.ok(
changesetInstance.get('isValid'),
'should be valid if content is passed into validator'
'should be valid if content is passed into validator',
);
});

Expand All @@ -152,18 +152,18 @@ module('Unit | Helper | changeset', function () {
changesetInstance.validate().then(() => {
assert.deepEqual(
changesetInstance.get('error').firstName.validation,
"[CUSTOM] First name can't be blank"
"[CUSTOM] First name can't be blank",
);
assert.ok(
changesetInstance.get('isInvalid'),
'should be invalid with wrong length first name'
'should be invalid with wrong length first name',
);

changesetInstance.set('firstName', 'Jim');
changesetInstance.set('lastName', 'Bob');
assert.ok(
changesetInstance.get('isValid'),
'should be valid after setting valid first and last names'
'should be valid after setting valid first and last names',
);
});
});
Expand All @@ -183,7 +183,7 @@ module('Unit | Helper | changeset', function () {
});
assert.ok(
changesetInstance.get('_options').skipValidate,
'option should have been passed through'
'option should have been passed through',
);

changesetInstance.set('firstName', '');
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/utils/get-messages-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module('Unit | Utility | get messages', function () {
assert.deepEqual(
getMessages(dummyModuleMap, false),
defaultMessages,
'loads the correct module'
'loads the correct module',
);
});
});
Loading

0 comments on commit d51c156

Please sign in to comment.